UNPKG

abb-core

Version:

Application Build Butler Core

71 lines (70 loc) 2.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var EABB_router_action_types_1 = require("./EABB-router-action-types"); var immutable_1 = require("immutable"); var ABBRouterActionCreator = /** @class */ (function () { function ABBRouterActionCreator() { } ABBRouterActionCreator.prototype.createRoutesReducer = function (initialState) { return function (state, action) { if (state === void 0) { state = initialState; } switch (action.type) { case EABB_router_action_types_1.default.ADD_ROUTE: return Object.assign({}, state, { routes: state.routes.insert(state.routes.size + action.offset, action.route) }); case EABB_router_action_types_1.default.DELETE_ROUTE: var routeIndex = state.routes.indexOf(action.route); return Object.assign({}, state, { routes: state.routes.delete(routeIndex) }); default: return state; } }; }; ABBRouterActionCreator.prototype.getReducersMapObject = function () { return { routesReducer: this.createRoutesReducer({ routes: immutable_1.List(), }) }; }; ABBRouterActionCreator.prototype.getStateToReducerMapObject = function (state) { return { routesReducer: { routes: state.routes } }; }; ABBRouterActionCreator.addRoutes = function (routes) { return function (dispatch) { routes.forEach(function (route) { dispatch(ABBRouterActionCreator.addRoute(route)); }); return Promise.resolve(); }; }; ABBRouterActionCreator.addRoute = function (route) { return { route: route, type: EABB_router_action_types_1.default.ADD_ROUTE, offset: -1 }; }; ABBRouterActionCreator.setNotFoundRoute = function (route) { return { route: route, type: EABB_router_action_types_1.default.ADD_ROUTE, offset: 0 }; }; ABBRouterActionCreator.deleteRoute = function (route) { return { route: route, type: EABB_router_action_types_1.default.DELETE_ROUTE }; }; return ABBRouterActionCreator; }()); exports.ABBRouterActionCreator = ABBRouterActionCreator;