oop-observer
TypeScript icon, indicating that this package has built-in type declarations

2.0.8 • Public • Published

OOP Obsever

observer - pattern that helps you to handle & dispath events

npm npm npm npm

IObservable

Event emitter interface. Contains subscribe, unsubscribe and notify methods.

Observable

Class with implementation IObservable interface. It's ready to work!

// define event props
interface TestObserverProps {
    test: string;
}

IObserver

Event listener interface. Has update function, that called with generic props.

class TestObserver implements IObserver<TestObserverProps> {
    update(args: TestObserverProps) {
        // event handler code
        console.log(args.test);
    }
}

Usage

When IObserver is defined just call notify method.

const observerable = new Observer<TestObserverProps>();
const observer = new TestObserver();

observerable.subscribe(observer);
observerable.notify({ test: "Some text here" });

📦 Install

npm i oop-observer

:octocat: Sources are available on github

Package Sidebar

Install

npm i oop-observer

Weekly Downloads

5

Version

2.0.8

License

MIT

Unpacked Size

10.4 kB

Total Files

13

Last publish

Collaborators

  • kostayne