1.0.4 • Published 2 years ago

@mrmeizongo/delegate v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Use this package to get a delegate object that can be used as a notification system.

The object that the delegate function returns has 4 methods; sub(element), desub(element), list() and exec().

Any function can subscribe to the delegate with the sub() method and the opposite with the desub method.

Call the list() method to get an array of the names of all subscribed functions to the delegate.

Call the exec() method where ever you want all the subscribed methods to be called.

Usage:

On the command line, enter:

npm install @mrmeizongo/delegate

In your code:

import delegate from '@mrmeizongo/delegate'
let myDel = delegate();
let myFunc1 = () => console.log("myFunc1");
let myFunc2 = () => console.log("myFunc2");

myDel.sub(myFunc1, myFunc2);

myDel.exec();
--> myFunc1
--> myFunc2

myDel.desub(myFunc2);

myDel.exec();
--> myFunc1

Both the sub() and desub() methods can take more than one argument.

Work is currently underway to try to make exec() asynchronous.

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago