0.2.5 • Published 6 years ago

abstract-observable v0.2.5

Weekly downloads
8
License
MIT
Repository
github
Last release
6 years ago

abstract-observable

Simple typescript abstract class for observer pattern.

Install

yarn add abstract-observable

or

npm install --save abstract-observable

1 - Create an observable class

export class WantToBeObserved extends Observable {
  public someAction() {
    // do stuff here then notify
    this.notify();
  }
}
const observableInstance = new WantToBeObserved();

2 - Create some observers

export class WantToObserve implements IObserver {
  public notify(): void {
    // do stuff here
  }
}
export function wantToObserveFunction(): void {
  // do some other stuff here
}

3 - Subscribe the observers

// subscribe class instance
const observerInstance = new WantToObserve();
const unsubscribeInstance = observableInstance.subscribe(observerInstance);

// subscribe function
observableInstance.subscribe(wantToObserveFunction);

// to unsubscribe call the return of subscribe
unsubscribeInstance();
0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.12

6 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago