A custom event registration, creation & subscription wrapper library
This library has no dependencies.
We use bower and npm for dependency management, run
bower install --save custom-event-manager
npm install --save custom-event-manager
This will copy the custom-event-manager files into your components folder, along with its dependencies.
<script type="text/javascript" src="bower_components/custom-event-manager/dist/javascript/custom-event-manager.min.js"></script>
<script type="text/javascript" src="node_modules/custom-event-manager/dist/javascript/custom-event-manager.min.js"></script>
Register custom events that are known at application start using the initialize function.
CustomEventManager.initialize({
"searchCompleted":{
"beforeEvent":function(data){...},
"afterEvent":function(data){...}
},
"searchInitialized":{
"beforeEvent":function(data){...},
"afterEvent":function(data){...}
}
});
Register custom events that are dynamically computed using the register function.
CustomEventManager.register("search_"+i+"_completed",{
"beforeEvent":function(data){...},
"afterEvent":function(data){...}
});
Subscribe to custom registered events using the subscribe function. The element argument defaults to document.querySelector('body')
CustomEventManager.subscribe("searchCompleted",function(data){
console.log(data.searchTerm);
console.log(data.resultCount);
});
Trigger custom registered events using the trigger function. The element argument defaults to document.querySelector('body')
CustomEventManager.trigger("searchCompleted",{
"searchTerm":"milk",
"resultCount":56
});