badmfck-signal
v1.4.9
Published
An implementation of a signaling mechanism used to connect components and transfer data between them
Downloads
129
Maintainers
Readme
#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!") }