0.3.0 • Published 3 years ago

@plancky/notifier v0.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Pure notifier implementation

A Notifier is an object that has a notify property. It can have subscribers that listen for that notify call and react to it. It's like an event emitter that only emits one type of event.

It can be either used directly:

  import Notifier from '@plancky/notifier';

  const notifier = new Notifier();

  const subscriber = () => {
    console.log('Something happened!');
  }

  notifier.subscribe(subscriber);

  notifier.notify(); // Logs "Something happened"

Or extended by another class:

  import Notifier from '@plancky/notifier';

  class DataNotifier extends Notifier {
    data = "hello"

    setData = (newData) => {
      this.data = newData;
      this.notify();
    }
  }

  const dataNotifier = new DataNotifier();
  dataNotifier.subscribe(() => {
    console.log(`The data changed! It is now ${dataNotifier.data}`);
  });

  dataNotifier.setData('bye'); // Logs "The data changed! It is now bye"
0.3.0

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago