Skip to content

Observer

Alexandre Moreau-Lemay edited this page Aug 22, 2022 · 2 revisions

Template to create a new observer.

Implementation

interface Observer<T> {
    update(subject: Store<T>): void;
}

The Store will trigger the method update when Store.set() or Store.notify() are triggered.

Methods

Update

update(subject: Store<T>): void;

Parameters

  • subject: Store<T>

    The Store the observer is attached to.

Example Observer

class ConcreteObserver implements Observer<number> {
    public update(subject: Store<number>) {
        console.log(subject.state);
    }
}

Clone this wiki locally