Skip to content

Commit

Permalink
add method "subscribeOnce",Subscribes the passed function to the pass…
Browse files Browse the repository at this point in the history
…ed message once
  • Loading branch information
Ryuurock committed Nov 23, 2017
1 parent 903eb3c commit fafd30d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,22 @@ https://github.com/mroderick/PubSubJS
return token;
};

/**
* PubSub.subscribeOnce( message, func ) -> PubSub
* - message (String): The message to subscribe to
* - func (Function): The function to call when a new message is published
* Subscribes the passed function to the passed message once
**/
PubSub.subscribeOnce = function( message, func ){
let token = pubsub.on( event, function(){
// before func apply, unsubscribe message
pubsub.unsubscribe( token );
func.apply( this, arguments );
} );

return PubSub;
}

/* Public: Clears all subscriptions
*/
PubSub.clearAllSubscriptions = function clearAllSubscriptions(){
Expand Down

0 comments on commit fafd30d

Please sign in to comment.