zurb / foundation-apps

The first front-end framework created for developing fully responsive web apps.
http://foundation.zurb.com/apps
MIT License
1.58k stars 215 forks source link

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

Open mattgrande opened 8 years ago

mattgrande commented 8 years ago

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 commented 8 years ago

Similar to https://github.com/zurb/foundation-apps/issues/804