@ima/core
Version:
IMA.js framework for isomorphic javascript application
61 lines (60 loc) • 2.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "PageHandlerRegistry", {
enumerable: true,
get: function() {
return PageHandlerRegistry;
}
});
const _PageHandler = require("./PageHandler");
const _GenericError = require("../../error/GenericError");
const _SerialBatch = require("../../execution/SerialBatch");
class PageHandlerRegistry extends _PageHandler.PageHandler {
_pageHandlers;
_preManageHandlers;
_postManageHandlers;
static ExecutionMethod = _SerialBatch.SerialBatch;
/**
* Creates an instance of HandlerRegistry and creates `SerialBatch`
* instance for pre-handlers and post-handlers.
* @memberof HandlerRegistry
*/ constructor(...pageHandlers){
super();
this._pageHandlers = pageHandlers;
}
/**
* @inheritDoc
*/ init() {
this._pageHandlers.forEach((handler)=>handler.init());
this._preManageHandlers = Reflect.construct(PageHandlerRegistry.ExecutionMethod, [
this._pageHandlers.map((handler)=>handler.handlePreManagedState.bind(handler))
]);
this._postManageHandlers = Reflect.construct(PageHandlerRegistry.ExecutionMethod, [
this._pageHandlers.map((handler)=>handler.handlePostManagedState.bind(handler))
]);
}
/**
* Executes the pre-manage handlers with given arguments
*/ handlePreManagedState(managedPage, nextManagedPage, action) {
if (!this._preManageHandlers) {
throw new _GenericError.GenericError('You must call init first.');
}
return this._preManageHandlers.execute(managedPage, nextManagedPage, action);
}
/**
* Executes the post-manage handlers with given arguments
*/ handlePostManagedState(managedPage, previousManagedPage, action) {
return this?._postManageHandlers?.execute(managedPage, previousManagedPage, action);
}
/**
* @inheritDoc
*/ destroy() {
this._pageHandlers.forEach((handler)=>handler.destroy());
this._preManageHandlers = undefined;
this._postManageHandlers = undefined;
this._pageHandlers = [];
}
}
//# sourceMappingURL=PageHandlerRegistry.js.map