0.1.2 • Published 9 years ago

kola-signals v0.1.2

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

Kola Signals

Statically-Typed For U implementation of signals. Use with Typescript but you can also use it for Javascript/Coffeescript.

Install via:

    npm install kola-signals --save

Quick guide

import signals = require('kola-signals');

var messenger:signals.Dispatcher<string> = new signals.Dispatcher<string>();

var receiver = (msg: string) => {
    console.log("message received!", msg);
}

messenger.listen(receiver);
messenger.dispatch("Hello Awesomeness!");

Use it in classes

import signals = require('kola-signals');

var smsService = new signals.Dispatcher<string>();

class Phone {

    msgs: string[];

    constructor() {
        this.msgs = [];
    }

    onReceiveMsg(msg:string):void {
        console.log("Message received!", msg);
        this.msgs.push(msg);
    }
}

var phone: Phone = new Phone();

smsService.listen(phone.onReceiveMsg, phone);

smsService.dispatch("Hi there!");

NOTE: In this example, we pass in the 'phone' as second argument for listen(). It allows the onReceiveMsg() to be called with 'this' as the 'phone' instance.

Call once

import signals = require('kola-signals');

smsDispatcher.listen(onceAFunction, null, true);

Unlisten

The listen() method of signals.Dispatcher returns an instance of signals.Listener. You can use this instance to call unlisten() like so:

var listener = smsService.listen(onReceiveMsg);

...

listener.unlisten();
0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago