typedux
Version:
Slightly adjusted Redux (awesome by default) for TS
58 lines • 2.88 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);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InternalActionFactory = void 0;
const ActionTypes_1 = require("../actions/ActionTypes");
const BaseActionFactory_1 = require("../actions/BaseActionFactory");
const ActionDecorations_1 = require("../actions/ActionDecorations");
const InternalState_1 = require("./InternalState");
const constants_1 = require("../constants");
const clone_1 = __importDefault(require("lodash/clone"));
class InternalActionFactory extends BaseActionFactory_1.BaseActionFactory {
constructor(store) {
super(InternalState_1.InternalState, store);
}
leaf() {
return constants_1.INTERNAL_KEY;
}
setPendingAction(action) {
return (state) => {
let newState = new InternalState_1.InternalState(state), pendingActions = Object.assign({}, newState.pendingActions), pendingAction = pendingActions[action.id], isFinished = action.status >= ActionTypes_1.ActionStatus.Finished;
if (!isFinished && !pendingAction) {
newState.totalActionCount++;
newState.pendingActionCount++;
}
else if (isFinished && pendingActions[action.id]) {
newState.pendingActionCount--;
}
newState.hasPendingActions = newState.pendingActionCount > 0;
if (!isFinished) {
pendingActions[action.id] = clone_1.default(action);
}
else {
delete pendingActions[action.id];
}
newState.pendingActions = pendingActions;
return newState;
};
}
}
__decorate([
ActionDecorations_1.ActionReducer(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], InternalActionFactory.prototype, "setPendingAction", null);
exports.InternalActionFactory = InternalActionFactory;
//# sourceMappingURL=InternalActionFactory.js.map