Closed zackferraro closed 10 years ago
If it is important to apply the handler against the window by default, then F2 can do a check substitution on that argument: var thisContext = (sub.context === defaultContext) ? window : sub.context; sub.handler.apply(thisContext, args);
+1 for the concern about events and the solution.
However, I'm not seeing from the eventEmitter2 api that it can be used in that way F2.off(null, null, window)
, or emitter.off(null, null, window)
?
Its in the v2-restructured branch: https://github.com/OpenF2/F2/blob/v2-restructured/src/events.js I don't know much of that branch is staying for v2 (if any), but in effort to learn it so I can better contribute I decided to write some unit tests for it, and this was an issue I couldn't think of a test description for.
@zackferraro Thanks for pointing out the flaw. I think we should be able to check the identity of the "context" param and default it to null
if it matches window
. Later we can default the handler execution context to window
if nothing else was provided.
I'll make the change.
Do we want to add this to #155?
@markhealey I don't believe v1 has this problem since it uses EventEmitter. As far as I know, you can't specify the context a handler executes in with anything other than $.proxy
or .bind()
.
Sorry, my bad—I misread the issue title! Back to regularly scheduled programming...
In the current working of event unsubscription, if an app registers an event without supplying context (which is allowed behavior), the context defaults to the window. If someone ever does F2.off(null, null, window), it will blow out all the context-less events.
Is this desired behavior?
If not, F2 should use a default context object that lives inside the Events closure.