typedux
Version:
Slightly adjusted Redux (awesome by default) for TS
51 lines • 2.43 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);
};
import { ActionStatus } from "../actions/ActionTypes";
import { BaseActionFactory } from "../actions/BaseActionFactory";
import { ActionReducer } from "../actions/ActionDecorations";
import { InternalState } from "./InternalState";
import { INTERNAL_KEY } from "../constants";
import _clone from "lodash/clone";
export class InternalActionFactory extends BaseActionFactory {
constructor(store) {
super(InternalState, store);
}
leaf() {
return INTERNAL_KEY;
}
setPendingAction(action) {
return (state) => {
let newState = new InternalState(state), pendingActions = Object.assign({}, newState.pendingActions), pendingAction = pendingActions[action.id], isFinished = action.status >= 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(action);
}
else {
delete pendingActions[action.id];
}
newState.pendingActions = pendingActions;
return newState;
};
}
}
__decorate([
ActionReducer(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], InternalActionFactory.prototype, "setPendingAction", null);
//# sourceMappingURL=InternalActionFactory.js.map