0.2.5 • Published 7 years ago

abstract-observable v0.2.5

Weekly downloads
8
License
MIT
Repository
github
Last release
7 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

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.12

7 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago