2.0.8 • Published 3 years ago

oop-observer v2.0.8

Weekly downloads
11
License
MIT
Repository
github
Last release
3 years ago

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" });

:package: Install

npm i oop-observer

:octocat: Sources are available on github

2.0.8

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago