stfu-signals
v0.0.4
Published
Simple signals implementation in javascript
Downloads
6
Readme
STFU! Signals
Statically-Typed For U implementation of signals. Use with Typescript but you can also use it for Javascript/Coffeescript.
Install via:
npm install stfu-signals --save
Quick guide
import signals = require('stfu-signals');
var messenger:signals.SignalDispatcher<string> = new signals.SignalDispatcher<string>();
var receiver = (msg: string) => {
console.log("message received!", msg);
}
messenger.addListener(new signals.SignalListener<string>(receiver));
messenger.dispatch("Hello Awesomeness!");
Use it in classes
import signals = require('stfu-signals');
var smsService = new signals.SignalDispatcher<string>();
class Phone {
smsSignalReceiver:signals.SignalListener<string>;
constructor() {
this.smsSignalReceiver = new signals.SignalListener<string>(this.onReceiveMsg, this);
}
onReceiveMsg(msg:string):void {
console.log("Message received!", msg);
}
}
var phone: Phone = new Phone();
smsService.addListener(phone.smsSignalReceiver);
smsService.dispatch("Hi there!");
Call once
import signals = require('stfu-signals');
var onceAListener:signals.SignalListener<string> = new signals.SignalListener(onceAFunction, null, true);
smsDispatcher.addListener(onceAListener);