Skip to content
simple events
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore mis.js : @ralphtheninja has a keen eye Oct 4, 2015
LICENSE
README.md README.md : usage, nodejs and browser Oct 4, 2015
index.html index.html : better example Oct 4, 2015
mis.js mis.js : @ralphtheninja has a keen eye Oct 4, 2015
package.json package.json : init Oct 4, 2015

README.md

mis

simple events

Usage

Node.js

mis exports a single function which can be used to bind callbacks local events.

var mis=require("mis");

var en=mis();

// create a callback stack for an 'each' event:
en('each',function(msg){
    console.log(msg);
});

// do something with the resulting callback:
var count=0;
setInterval(function(){
    en('each')(count++);
},1000);

In the browser

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" charset="UTF-8">
        <script src="mis.js"></script>
<body>
<script>
// call mis() as many times as you want.
// It returns a new, unique set of stacks each time.
var en=mis();

// calling it with no arguments returns its internal state:
    // hooks (object), stacks (object), place(function)

// place initializes a stack with whatever name you pass
// once initialized, it's safe to call that stack
    // (your own functions still have to work, though)
en().place('each');

var countDown=10;
var interval=window.setInterval(function(){
    en('each')(countDown--);
},1000);

// add a function to the list to be called on each iteration of the interval
en('each',function(n){
    console.log(n);
});

en('done',function(){
    window.clearInterval(interval);
    console.log("Blast off!");
});

// push as many as you want
en('each',function(msg){
    if(countDown == 0){
        en('done')();
    }
});
</script>
You can’t perform that action at this time.