trigger.js
v0.0.2
Published
Trigger registered functions on state change(enter or exit) for async tasks
Downloads
6
Readme
Introduction
Trigger.js is an utility function library that can either been adopted in a web browser or node.js.
Trigger.js persists the effect of event, when an event is on, all of the listener function under this event will be triggered; when new function is registered to an event that is available, the function will be invoked immediately.
Usage
For usage see the test/trigger.js for detail
An easy version of this function protect function to be invoked before initialized.
var $P = (function () {
var trigger = require('trigger.js')
var invoker = function (fn) {
return invoker.m.wrap('initialized', fn);
};
invoker.m = trigger('unknown');
invoker.initialize = function () {
invoker.m('initialized');
}
return invoker;
})();
Use the function in this way
var some;
setTimeout(function () {
some = 10;
$P.initialize();
}, 1000);
var print = $P(function(a, b) {
console.log(a + b ^ some);
});
print(1, 2)
The log will be printed after some have been initialized as 10.