-
-
Save adnasa/02902f327c337427f39b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! Js Pub/Sub | |
* http://anasnakawa.com/ | |
* Copyright (c) Anas Nakawa | |
* inspired by Ben Alman's one <https://gist.github.com/cowboy/661855> | |
* MIT License | |
*/ | |
(function( p ) { | |
var e = p.e = {}; | |
p.publish = function( name, data ) { | |
( e[ name ] = e[ name ] || new Event( name ) ).data = data; | |
dispatchEvent( e[ name ] ); | |
}; | |
p.subscribe = function( name, handler, context ) { | |
addEventListener( name, handler.bind( context ) ); | |
}; | |
p.unsubscribe = function( name, handler, context ) { | |
removeEventListener( name, handler.bind( context ) ); | |
}; | |
})( this.pubsub = {} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment