JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q15076F
  • License MIT

traditional observer pattern realization

Package Exports

  • oop-observer

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (oop-observer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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