Skip to content

koinejs/Publisher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Koine Publisher

Publisher/Subscriber implemenation

Code information:

Build Status Coverage Status Code Climate

Package information:

Dependency Status

Usage

var publisher = new Koine.Publisher();

var callback = function (event) {
    var oldName = event.data.oldName;

    console.log('Changed name of user from "' + oldName + '" to "' + this.name + '"');
}

publisher.subscribe('change:username', callback);

user.updateName = function (name) {
    var oldName = this.name;

    if (oldName === name) {
        return;
    }

    var event  = new Koine.Publisher.EventType("change:username", user);
    event.data = { oldName: oldName };
    publisher.publish(event);
};


publisher.clearSubscriptions();                     // remove all subscriptions
publisher.unsubscribe('change:userame');            // all the change:username callbakcs
publisher.unsubscribe('change:username', callback); // only the given callback

Enabling triggers on Objects

var MyClass = function () {};
MyClass.prototype.sayHello = function () {};

Koine.Publisher.wrap(MyClass);

var object = new MyClass();

object.on('sayHello', function (e) {
    alert(['Hello', e.name].join(' '), '!');
});


var event  = new Koine.Publisher.EventType("sayHello");
event.name = "World";

object.trigger(event); // alert('Hello World !')

Installing

@TODO

Issues/Features proposals

Here is the issue tracker.

Contributing

Please refer to the contribuiting guide.

Lincense

MIT

Authors

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors