Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

sig3

0.0.9 • Public • Published

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!

Install

npm i sig3

DownloadsWeekly Downloads

21

Version

0.0.9

License

MIT

Unpacked Size

328 kB

Total Files

22

Last publish

Collaborators

  • avatar