trigger.js

0.0.2 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i trigger.js

Weekly Downloads

2

Version

0.0.2

License

MIT

Last publish

Collaborators

  • shinohane