export class TRRCStore {

    constructor() {
        this.state = {
            root: null,
            current: null,
            history: []
        };
    }

    load(data) {
        this.state.root = data;
        this.state.current = data;
    }

    getState() {
        return this.state;
    }

    goToChild(id) {

        const found =
            this.state.current.children?.find(x => x.id == id);

        if (found) {

            this.state.history.push(this.state.current);

            this.state.current = found;

        }
    }

    goBack() {

        if (this.state.history.length > 0) {

            this.state.current = this.state.history.pop();

        }
    }

    goHome() {

        this.state.current = this.state.root;

        this.state.history = [];

    }

}
