README
sig3.js
javascript micro-library signal system π‘ - ts migration - wip.
Problemβ
no problem
, just wanna create something following the observer pattern.
Solutionβ
this micro-library can do the job for you. it leaves you the possibility of deploying satellites
anywhere in your application. each satellite
can be recorded on a specific channel which will be triggered by the local station
when it has transmitted the information through a signal
. in this way your satellites will be kept informed when the station
updates data.
β οΈ Disclaimer
I'm not a developer, so some changes will be expected in the future for the benefit of all, I hope.
π¦ Install dependencies
Command line
npm i sig3
OR
yarn add sig3
Download
You can also, download the repo, recover the file which is in build/sig3.js
then free to you to place it in the place of your choice in your project.
π Start project
import * as sig3 from 'sig3';
OR
import { Station, Satellite } from 'sig3';
π» Demo
const state = { count: 0 };
const _operation = [
state => {
state.count = state.count + 1;
console.log( state );
return state;
},
state => {
state.count = state.count + 5;
console.log( state );
return state;
}
];
const station = new sig3.Station();
station
.onsignal( 'event:onready', {
before: () => console.log( 'before' ),
error: () => console.log( 'error' ),
after: () => console.log( 'after' )
} )
.prepare( state, _operation )
.transmit();
/* output:
before
{ count: 1 }
{ count: 6 }
after
*/
π API
Station()
creates a local
station
to handle the management of the satellites deployed but also the transmission of instructions to satellites.params
no params
example
const station = new Station(); // output: Station {onsignal: Ζ, offsignal: Ζ, transmit: Ζ, transmitAll: Ζ, value: Ζ}
.onsignal( name, callback )
prepares the emission of a signal by recording the
callback
passed in argument on a dedicated channel also defined in argument. several satellites can be connected to the samesignal
.params
name
{ String }: name of the corresponding signal.
callback
{ Function } callback.
returns
{ Object }:this
.example
station.onsignal( 'event:onready', { before: () => console.log( 'before' ), error: () => console.log( 'error' ), after: () => console.log( 'after' ) } ); // outuput: true
.offsignal( name )
stops the emission of a
signal
by deleting the satellite(s) attached to the correspondingsignal
.params
name
{ String }: name of the corresponding signal.
returns
{ Boolean }:this
.example
station.offsignal( 'event:onready' ); // outuput: true
.transmit()
to transmit instructions to the satellite(s) via a
signal
connected to a dedicated channel.params
no params
returns
{ Boolean }:this
.example
station.transmit(); // output: true
.transmitAll()
to transmit instructions to the satellite(s) via a
signal
connected to a dedicated channel.params
no params
returns
{ Boolean }:this
.example
station.transmit(); // output: true
π¨ Tests
reports
npm run test:reports
OR
yarn test:reports
watch
npm run test:watch
OR
yarn test:watch
Coverage
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
---|---|---|---|---|---|
All files | 92.31 | 90 | 80 | 100 | |
sig3.satellite.ts | 100 | 100 | 100 | 100 | |
sig3.station.ts | 91.3 | 90 | 75 | 100 | 16 |
π Todo
- async feature
- add examples
- improve test cases
π Source
Β©οΈ License
Copyright Β©οΈ 2019 monsieurbadia
Released under the MIT license
π Supports
logo with π€ by @mllemartins
built with π€ by @monsieurbadia
βοΈ this repository if this project helped you!