State pattern example of typescript

Osho 11 months ago updated 11 months 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.