Created
June 2, 2016 17:37
-
-
Save masudiiuc/69fc499269b6caa1111879df3fe3bdb2 to your computer and use it in GitHub Desktop.
Add listener to dispatch events
This file contains 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
var utitlity = (function(){ | |
'use strict'; | |
var observerList = []; | |
var observe = function (eventName, eventMethod) { | |
observerList[eventName] = eventMethod; | |
}; | |
var dispatch = function (eventName, eventParams){ | |
eventParams = eventParams || ''; | |
if (observerList.indexOf(eventName)) { | |
if (typeof observerList[eventName] === 'function') { | |
observerList[eventName].call(this, eventParams); | |
} | |
} | |
}; | |
var clearObserverList = function () { | |
observerList = []; | |
}; | |
var getObserverList = function () { | |
return observerList; | |
}; | |
return { | |
observe : observe, | |
dispatch : dispatch, | |
clearObserverList: clearObserverList, | |
getObserverList: getObserverList | |
}; | |
})(); | |
utitlity.observe('addElement', function (count) { | |
console.log('Called >>> ', count + 1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment