ts-observer-pattern
A simple observer pattern implementation in TypeScript.
npm install ts-observer-pattern
Example
In the example that follows, I'm implementing a relationship bettween a magazine and it subscribers
import { Subject } from 'ts-observer-pattern'
class Magazine extends Subject
{
private Observers: Observers[]
public publish()
{
this.Observer.notify("New edition available")
}
}
import { Observer } from 'ts-observer-pattern'
class Subscriber implements Observer
{
public update(data): this
{
}
}
import { Magazine } from './Magazine'
import { Subscriber } from './Subscriber'
let Coders = new Magazine
let Matt = new Subscriber
let Ana = new Subscriber
Coders.attach(Matt)
Coders.attach(Ana)