export class StateParser {
    onStart() {
        this.state = {};
    }
    parseModule(pageId, mod) {
        var _a;
        const stateObj = ((_a = mod.exports) === null || _a === void 0 ? void 0 : _a.default) || mod.exports;
        if (typeof stateObj === 'object') {
            // FIXME
            const plain = JSON.parse(JSON.stringify(stateObj)); // Creating observable from object defined in another context(lowcode state is executed in the iframe) will fail
            this.state[pageId] = plain;
        }
        else if (typeof stateObj === 'function') {
            const plain = JSON.parse(JSON.stringify(stateObj.call())); // Creating observable from object defined in another context(lowcode state is executed in the iframe) will fail
            this.state[pageId] = plain;
        }
        else {
            throw new Error('state must export an object or function');
        }
    }
    onEnd(context) {
        context.state = this.state;
    }
}
