State pattern example of typescript

Osho 1 year ago updated 1 year ago 0

Hi, there is lack of code in State pattern example of typescript.

This code needs "state.setContext()" in constructor of Context class maybe.
Like this,

class Context {
     * @type {State} A reference to the current state of the Context.
    private state: State;

    constructor(state: State) {
        this.state.setContext(this); // add setContext() for state

Please check this example.

Thank you.