Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A simple pub/sub JavaScript utility

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 README
Octocat-spinner-32 pubsub.js
README
A dead simple pub/sub javascript library with priority having no third-party dependencies. Inspired by the original work of the AS3 event model which is pretty delicious.

NOTE: This work is over 2.5 years old, could be tuned and is in need of some loving. 

-- start snip --
function foo1(event){
    console.log("foo1 called.")
    event.preventDefault();
}
function foo2(){
    var str = "";
    for(var i=0; i<100000; i++){
        str += "f" + new Date();
    }
    console.log("foo2 called");
}
function foo3(){
    console.log("foo3 called")  
}

var myEvent1 = new Subject("PreventDefaultExample");
myEvent1.addEventListener(foo1, 1);
myEvent1.addEventListener(foo2, 1);//will never be called because foo1 preventDefault on event
myEvent1.addEventListener(foo3, 1);//will never be called because foo1 preventDefault on event
myEvent1.dispatchEvent(false);


var myEvent2 = new Subject("PreventDefaultExample");
myEvent2.addEventListener(foo1, 3);//will be called first due to highest priority
myEvent2.addEventListener(foo2, 2);//will be called second...
myEvent2.addEventListener(foo3, 1);//will be called last
myEvent2.dispatchEvent(false);
-- end snip --
Something went wrong with that request. Please try again.