Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

There is no way to unsubscribe from only one listener #814

Open
mattgrande opened this issue May 19, 2016 · 1 comment
Open

There is no way to unsubscribe from only one listener #814

mattgrande opened this issue May 19, 2016 · 1 comment

Comments

@mattgrande
Copy link

You can subscribe to the same event multiple times without issue:

FoundationApi.subscribe( 'myModal', _callbackA );
FoundationApi.subscribe( 'myModal', _callbackB );

Internally (in foundation.core.js, function subscribe), this adds the callbacks to a listeners array:

`listeners[name].push(callback);`

It's implied in #806 that unsubscribing in this manner:

FoundationApi.unsubscribe( 'myModal', _callbackA );

would unsubscribe from _callbackA, while leaving _callbackB in tact. However, when inspecting the code, no matter what, all listeners are deleted (foundation.core.js, function unsubscribe):

delete listeners[name];

If a developer adds listeners to a modal, then later unsubscribes from them, the internal modal's listener is removed, causing that modal to stop working.

@soumak77
Copy link
Contributor

Similar to #804

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants