react-application-core
Version:
A react-based application core for the business applications.
122 lines • 5.7 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RouterEffects = void 0;
var redux_effects_promise_1 = require("redux-effects-promise");
var ts_smart_logger_1 = require("ts-smart-logger");
var util_1 = require("../util");
var di_1 = require("../di");
var definition_1 = require("../definition");
var RouterEffects = /** @class */ (function () {
function RouterEffects() {
}
RouterEffects_1 = RouterEffects;
RouterEffects.prototype.$onRewrite = function (action) {
this.router.go(-this.router.length);
var pathAndState = this.asFluxEntity(action);
RouterEffects_1.logger.debug("[$RouterEffects][$onRewrite] Path: " + pathAndState.path + ", state: " + pathAndState.state);
this.router.replace(pathAndState.path, pathAndState.state);
};
RouterEffects.prototype.$onNavigate = function (action) {
var pathAndState = this.asFluxEntity(action);
RouterEffects_1.logger.debug("[$RouterEffects][$onNavigate] Path: " + pathAndState.path + ", state: " + pathAndState.state);
this.router.push(pathAndState.path, pathAndState.state);
};
/**
* @stable [30.05.2019]
* @param {IEffectsAction} action
*/
RouterEffects.prototype.$onReplace = function (action) {
var pathAndState = this.asFluxEntity(action);
RouterEffects_1.logger.debug("[$RouterEffects][$onReplace] Path: " + pathAndState.path + ", state: " + pathAndState.state);
this.router.replace(pathAndState.path, pathAndState.state);
};
/**
* @stable [18.12.2019]
* @param {IEffectsAction} action
*/
RouterEffects.prototype.$onBack = function (action) {
var payload = action.data;
RouterEffects_1.logger.debug('[$RouterEffects][$onBack] Payload:', payload);
if (util_1.ObjectUtils.isObjectNotEmpty(payload)) {
if (util_1.TypeUtils.isNumber(payload.depth)) {
this.router.go(-payload.depth);
return;
}
}
this.router.goBack();
};
/**
* @stable [17.11.2019]
*/
RouterEffects.prototype.$onReload = function () {
RouterEffects_1.logger.debug('[$RouterEffects][$onReload]');
this.domAccessor.reload(true);
};
/**
* @stable [21.01.2021]
* @param action
* @private
*/
RouterEffects.prototype.asFluxEntity = function (action) {
var path = action.data;
if (util_1.TypeUtils.isString(path)) {
return { path: path };
}
return action.data;
};
var RouterEffects_1;
RouterEffects.logger = ts_smart_logger_1.LoggerFactory.makeLogger('RouterEffects');
__decorate([
di_1.lazyInject(di_1.DI_TYPES.DomAccessor),
__metadata("design:type", Object)
], RouterEffects.prototype, "domAccessor", void 0);
__decorate([
di_1.lazyInject(di_1.DI_TYPES.Router),
__metadata("design:type", Object)
], RouterEffects.prototype, "router", void 0);
__decorate([
redux_effects_promise_1.EffectsService.effects(definition_1.$RAC_ROUTER_REWRITE_ACTION_TYPE),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], RouterEffects.prototype, "$onRewrite", null);
__decorate([
redux_effects_promise_1.EffectsService.effects(definition_1.$RAC_ROUTER_NAVIGATE_ACTION_TYPE),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], RouterEffects.prototype, "$onNavigate", null);
__decorate([
redux_effects_promise_1.EffectsService.effects(definition_1.$RAC_ROUTER_REPLACE_ACTION_TYPE),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], RouterEffects.prototype, "$onReplace", null);
__decorate([
redux_effects_promise_1.EffectsService.effects(definition_1.$RAC_ROUTER_NAVIGATE_BACK_ACTION_TYPE),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], RouterEffects.prototype, "$onBack", null);
__decorate([
redux_effects_promise_1.EffectsService.effects(definition_1.$RAC_ROUTER_RELOAD_ACTION_TYPE),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], RouterEffects.prototype, "$onReload", null);
RouterEffects = RouterEffects_1 = __decorate([
di_1.provideInSingleton(RouterEffects_1)
], RouterEffects);
return RouterEffects;
}());
exports.RouterEffects = RouterEffects;
//# sourceMappingURL=router.effects.js.map