mikehostetler / amplify

AmplifyJS
http://amplifyjs.com
GNU General Public License v2.0
1.45k stars 144 forks source link

Not an issue, a suggestion... for pubsub #113

Open leolems opened 9 years ago

leolems commented 9 years ago

in the core, add: To remove topics, i had a need for it, because i needed to reset

//================================================
// custom function LLS
//================================================
removeTopic: function(topic) {
    if ( typeof topic !== "string" ) {
        throw new Error( "You must provide a valid topic to remove it." );
    }

    for(var name in subscriptions) {
        if (name === topic) {
            delete subscriptions[topic];
            break; 
        }
    }
}
bennycode commented 9 years ago

Great idea!

We use amplify to build Wire for Web and also needed a solution to unsubscribe all callbacks for a specific topic. That's why I created a Pull Request (mikehostetler/amplify#118) which makes the following possible:

amplify.unsubscribeAll(); // Unsubscribes all callbacks for all topics
amplify.unsubscribeAll('ButtonClicked'); // Unsubscribes all callbacks for a specific topic

Reference: https://github.com/mikehostetler/amplify/pull/118