badmfck-signal
TypeScript icon, indicating that this package has built-in type declarations

1.4.5 • Public • Published

#An implementation of a signaling mechanism used to connect components and transfer data between them

How to use: Create an instance of Signal with prefered data type: const S_TEST:Signal=new Signal()

Subscribe to signal, obtain callback id. const callbackID = S_TEST.subscribe(str=>{console.log(str)})

Call invokation procedure S_TEST.invoke("test")

Remove subscribtion, using id: S_TEST.remove("test1")

Remove all subscribtions from signal: S_TEST.clear();

shortcuts:

Subscribe to signalling pipe with name stored in group. group is optional, if not exists, global pipeline will use s_subscribe(group)

s_unsubscribe(id) unsubscribe from signal

The main principle is using one point in project to store all major interactions between sources without connectig them directly, also called as GlobalDispatcher or Spine.

example: file: GlobalDispatcher.ts export class GD{ static S_SAVE_DATA:Signal=new Signal(); }

file: DataManager.ts export GD from './GD' export class DataManager{ constructor(){ GD.S_SAVE_DATA.subscribe(data=>{ console.log(${data} saved!) }) } }

file: ViewController.ts export GD from './GD' button.onClick=()=>{ GD.S_SAVE_DATA.invoke("Test!") }

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i badmfck-signal

      Weekly Downloads

      13

      Version

      1.4.5

      License

      MIT

      Unpacked Size

      38.3 kB

      Total Files

      9

      Last publish

      Collaborators

      • badmfckm