Last but not least I think it would be also quite nice to have another
ISignal implementation that behaves like Signal but is dead simple and
does no verification at all. That way, you as a user of the signals
library can use the Signal clas in debug mode (to get nice error
messages) and switch to the FastSignal for production code.
Please tell me what you think.
https://github.com/joa/as3-signals/blob/master/src/org/osflash/signals/SignalBinding.as#L182
How about turning swap() into:
function set listener(value:Function):void
Then:
binding.listener = listener2;
Robert
https://github.com/joa/as3-signals/blob/master/src/org/osflash/signals/SignalBinding.as#L187
https://github.com/joa/as3-signals/blob/master/src/org/osflash/signals/Signal.as#L168
Robert
> I have seen the public
> IEventDispatcher.dispatchEvent abused far too many times, I'd really
> love it to be removed from IEventDispatcher similarly. For the
> aforementioned average use case, where the user will want to add,
> dispatch, and removeAll from the same signal, I'm of the mind that
> they should be ignoring the interface entirely as they are really
> after the full functionality of the Signal implementation. I have
> found restricting access to the dispatch method invaluable, I'd hate
> to see it exposed.
How is the lack of a dispatch invaluable?
I've found it to be a pain when I was writing APIs with Signals
support. I certainly didn't want to use a specific Signal
implementation. I've privately yearned for an interface that
represented this basic expected functionality.
IEventDispatcher that doesn't have the means to dispatch an event
seems even weirder ;)
I have seen the publicIEventDispatcher.dispatchEvent abused far too many times, I'd really
love it to be removed from IEventDispatcher similarly.
If I make my getters return ISignal then I can only do genuine gui testing, because my test can't dispatch() on the view's behalf.
I have scratched my head but I can't find a neat way around it.
Classic - I use 'support mocks' all the time for models and VOs - and in the VO situation it's also to allow me to change properties on an immutable VO for ease of testing... but it never occurred to me to take that approach with views/signals.
I can see how a support wrapper with methods like dispatchSomeSignal(valuesThatMatchTheSignalValues...) would work, and is declarative.
I use Roboteyes rather than FlexMonkey (as I don't use flex) and I do dig down into the display list to fire events for integration tests - but you can end up having to do a whole bunch of set up on the view as well, if it passes values from its form fields for example.
However... doesn't the library situation make it harder? Especially if the utility creator has made the signals private rather than protected and so you can't extend the class to get access?
I don't run into any problems with testing via the eventDispatcher - where we can dispatchEvent() - and I haven't found any problems with my Signals test approach being the same.
In my experience, incorrect use of private vs protected is more common than abusing the ability to dispatch from outside - but perhaps that's not our problem to fix?
What do you think? A way to aggregate multiple native events with one
signal.
This is useful and someone asked for something like this a few weeks ago.
Robert
You didn't *have* to duplicate that much code; that's what you chose to do. =)
The concept behind NativeSignal is to use the native EventDispatcher
as much as possible, while adding Signal features on top. "Running
close to the metal"--not for performance reasons but in order to make
fewer assumptions about how EventDispatcher does what it does, and who
else is using it outside of Signals.
///////// Review for others
The main difference in the pre-Joa version is that--
nativeSignal.add(func);
--will directly call target.addEventListener(func). The listener is
directly wired to the EventDispatcher and when it dispatches, there is
no intermediary.
With nativeSignal.addOnce(func), we have to create an intermediary
that calls nativeSignal.remove(func) and then func(). But still there
is a one-to-one correspondence.
The NativeRelaySignal approach is to add a custom handler to the
EventDispatcher that will catch native dispatches and relay them to
the signal's listeners. The difference from NativeSignal was that if
NativeRelaySignal added 5 listeners, it would only have added one
listener to the EventDispatcher.
What Joa did was code the NativeRelaySignal approach into
NativeSignal, seen here:
My concern with abolishing the close-to-the-metal approach of
NativeSignal is that it may be messy in some use cases where normal
addEventListener() calls are mixed with signals, especially where
bubbling or priority is involved.
For example, if two listeners are given priorities 1 and 3 with
addEventListener() and two other listeners are giving priorities 2 and
4 with NativeSignal, how can they be called in the right order with
Joa's latest NativeSignal? I don't have a unit test for this but it
would be a good one.
Robert
To me, "bare-bones" implies fewer features, but NativeSignal has
essentially the same features as NativeRelaySignal.
I would argue that the current NativeSignal is "more native" than is
NativeRelaySignal.
> What aboud having a different kind of native signal that is doing what
NativeSignal in the original code was doing?
By "different kind" do you mean a simple rename, or something else?
Robert
Can you describe your use case for the ...params arguments? I'm struggling to think of one that wouldn't be more elegantly solved in the class where the handler is.If you know what the args are at the point of adding the handler, wouldn't it make more sense to create the handler function at runtime with those args already inside it?
Obviously valueClasses is still needed at a protected level - my concern about removing it from the public API is that you then force people to add functionality by extension rather than composition - though I guess they could always create a wrapper interface that included the valueClasses, extend just adding that getter and then compose from there.
I think it has value as a quick-debugging-of-black-box-code tool as well. If I'm trying to work with your code and I'm not sure what the value classes order is, I can just trace someSignal.valueClasses and I'm golden in 30 seconds ... but perhaps that's a weak use case?
I'll add that valueClasses is central to what a Signal aspires to be:
a multi-cast type-safe delegate. We can't currently express that
pattern very elegantly in AS3 compared to other languages. But if/when
we get generics and function types, look out.
The reason valueClasses was recently made writable was to enable MXML
definition, e.g.:
<!-- With Flex SDK 4, a single value class can go in the attribute,
using only curly braces.
With Flex SDK 3, it must be wrapped in an array: {[Boolean]} -->
<signals:Signal id="tabEnabledChanged" valueClasses="{Boolean}"/>
<!-- Wrap multiple value classes in square braces. -->
<signals:Signal id="tabIndexChanged" valueClasses="[int, Boolean]"/>
Robert
The library is still under development - and until it's 1.0 then there's no real 'rules' regarding semantic versioning - at which point I have no doubt that Robert will absolutely follow the versioning rules because he's a stickler for them as far as I can tell.
Early adoption has its drawbacks. The feedback that comes from the 0.x releases should be used to shape the 1.x release API, but to suggest that because some people have started using it before it was a 1.0, there can be no 'breaking' changes for the 1.0 release is just unworkable. That's the whole point of a beta release - that you know it's not right yet and you need to find out what's not right about it.
Stray
How do I know when to release 1.0.0?If your software is being used in production, it should probably already be 1.0.0. If you have a stable API on which users have come to depend, you should be 1.0.0. If you're worrying a lot about backwards compatibility, you should probably already be 1.0.0.
A few months ago I thought Signals had stabilized and was on the verge
of a 1.0. But then Joa entered the picture. =) The level of
discussion on the list has shot up as well. I would like the 1.0 to
include these developments. For example, I'm so over ISignalOwner and
IDispatcher and I and I'd rather not drag them around until 2.0.
I would like to see specific topics in these long discussions split
into separate threads so we can hash them out, decide and implement.
Robert
It feels like we can get to 1.0 within a few months. Starting 3 weeks
from now I'll have a lot more free time. As in order of magnitude. =)
Robert