Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

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();

About

Simple Signals implemented in Typescript - Statically Typed For U!

Resources

License

Packages

No packages published
You can’t perform that action at this time.