1.0.1 • Published 8 years ago
flux-emitter v1.0.1
FluxEmitter
- A muzchi/flumpt porting for general script with TypeScript.
Install
npm install --save flux-emitter
Usage
import { FluxEmitter } from 'flux-emitter';
import Promise from 'ts-promise';
const assert = require('assert');
function sleep(ms: number = 100) {
return new Promise((done) => { setTimeout(done, ms) });
}
const initialState = { count: 0 };
const fluxEmitter = new FluxEmitter(initialState);
var capture: any = null;
fluxEmitter.on(':flux-apply', (s: any) => {
// your code is here,
// for exmaple:
capture = s;
});
(async function () {
const p1 = fluxEmitter.update(async function (s) {
await sleep(100);
return { count: 3 };
});
await p1;
assert.deepEqual( capture, { count: 3 } );
})();
Middlewares
interface Middleware {
apply <T>(state: T|Thenable<T>): T|Thenable<T>
}
Copyrights
Original idea and implementation is written by mizchi, and mizchi/flumpt is under the MIT-license.
Author
Naoki OKAMURA (Nyarla) nyarla@thotep.net
License
MIT