Socket
Book a DemoInstallSign in
Socket

abstract-observable

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abstract-observable

Simple typescript abstract class for observer pattern.

0.2.5
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

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();

FAQs

Package last updated on 11 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.