Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var _CustomEvent = (function(){
- function _CustomEvent(name, callbacks){
- this.name = name;
- this.callbacks = callbacks || [];
- }
- _CustomEvent.prototype.registerCallback = function(callback){
- this.callbacks.push(callback);
- }
- return function(name, callbacks){
- return new _CustomEvent(name, callbacks);
- }
- })();
- var _Reactor = (function(){
- function _Reactor(events){
- this.events = events || {};
- }
- _Reactor.prototype.exists = function(eventName){
- return this.events.hasOwnProperty(eventName);
- }
- _Reactor.prototype.addEventListener = function(eventName, callback){
- if(!this.exists(eventName)){
- this.events[eventName] = new _CustomEvent(eventName);
- }
- this.events[eventName].registerCallback(callback);
- }
- _Reactor.prototype.dispatchEvent = function(eventName, eventArgs){
- this.events[eventName].callbacks.forEach(function(callback){
- callback(eventArgs);
- });
- }
- return function(events){
- return new _Reactor(events);
- }
- })();
- export default _Reactor;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement