UNPKG

@ima/core

Version:

IMA.js framework for isomorphic javascript application

150 lines (149 loc) 3.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "AbstractExtension", { enumerable: true, get: function() { return AbstractExtension; } }); const _Extension = require("./Extension"); const _GenericError = require("../error/GenericError"); class AbstractExtension extends _Extension.Extension { static $name; static $dependencies; /** * State manager. */ _pageStateManager; /** * Flag indicating whether the PageStateManager should be used instead * of partial state. */ _usingStateManager = false; _partialStateSymbol = Symbol('partialState'); /** * The HTTP response code to send to the client. */ status = 200; /** * The route parameters extracted from the current route. */ params = {}; /** * @inheritDoc */ init() { return; } /** * @inheritDoc */ destroy() { return; } /** * @inheritDoc */ activate() { return; } /** * @inheritDoc */ deactivate() { return; } /** * @inheritDoc */ load() { throw new _GenericError.GenericError('The ima.core.extension.AbstractExtension.load method is abstract ' + 'and must be overridden'); } /** * @inheritDoc */ update(prevParams = {}) { return {}; } /** * @inheritDoc */ setState(statePatch) { if (this._pageStateManager) { this._pageStateManager.setState(statePatch); } } /** * @inheritDoc */ getState() { if (this._usingStateManager && this._pageStateManager) { return this._pageStateManager.getState(); } else { return this.getPartialState(); } } /** * @inheritDoc */ beginStateTransaction() { if (this._pageStateManager) { this._pageStateManager.beginTransaction(); } } /** * @inheritDoc */ commitStateTransaction() { if (this._pageStateManager) { this._pageStateManager.commitTransaction(); } } /** * @inheritDoc */ cancelStateTransaction() { if (this._pageStateManager) { this._pageStateManager.cancelTransaction(); } } /** * @inheritDoc */ setPartialState(partialStatePatch) { const newPartialState = Object.assign({}, this[this._partialStateSymbol], partialStatePatch); this[this._partialStateSymbol] = newPartialState; } /** * @inheritDoc */ getPartialState() { return this[this._partialStateSymbol] || {}; } /** * @inheritDoc */ clearPartialState() { this[this._partialStateSymbol] = {}; } /** * @inheritDoc */ setRouteParams(params = {}) { this.params = params; } /** * @inheritDoc */ getRouteParams() { return this.params; } /** * @inheritDoc */ setPageStateManager(pageStateManager) { this._pageStateManager = pageStateManager; } /** * @inheritDoc */ switchToStateManager() { this._usingStateManager = true; } /** * @inheritDoc */ switchToPartialState() { this._usingStateManager = false; } /** * @inheritDoc */ getHttpStatus() { return this.status; } /** * Returns array of allowed state keys for extension. */ getAllowedStateKeys() { return []; } } //# sourceMappingURL=AbstractExtension.js.map