sig3

javascript micro-library signal system πŸ“‘ - ts migration - wip.

Usage no npm install needed!

<script type="module">
  import sig3 from 'https://cdn.skypack.dev/sig3';
</script>

README

sig3.js NPM Package Build Size NPM Downloads Dev Dependencies

javascript micro-library signal system πŸ“‘ - ts migration - wip.

english

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 same signal.

      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 corresponding signal.

      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!