2019-10-22 22:15:08 +00:00
|
|
|
"use strict";
|
2019-11-05 01:34:14 +00:00
|
|
|
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;
|
|
|
|
};
|
2019-10-24 15:52:36 +00:00
|
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
|
|
};
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
const fp_1 = __importDefault(require("lodash/fp"));
|
2019-11-05 01:34:14 +00:00
|
|
|
const mobx_1 = require("mobx");
|
2019-10-24 15:52:36 +00:00
|
|
|
const buildActions_1 = __importDefault(require("./buildActions"));
|
|
|
|
const buildInitial_1 = __importDefault(require("./buildInitial"));
|
|
|
|
const buildMutations_1 = __importDefault(require("./buildMutations"));
|
|
|
|
const buildCreateStore_1 = __importDefault(require("./buildCreateStore"));
|
|
|
|
const buildMiddleware_1 = __importDefault(require("./buildMiddleware"));
|
|
|
|
const buildUpreducer_1 = __importDefault(require("./buildUpreducer"));
|
2019-11-05 01:34:14 +00:00
|
|
|
var buildActions_2 = require("./buildActions");
|
|
|
|
exports.actionCreator = buildActions_2.actionCreator;
|
2019-10-22 22:15:08 +00:00
|
|
|
class Updux {
|
2019-11-05 01:34:14 +00:00
|
|
|
constructor(config = {}) {
|
|
|
|
this.groomMutations = config.groomMutations || ((x) => x);
|
2019-10-24 15:52:36 +00:00
|
|
|
this.subduxes = fp_1.default.mapValues((value) => fp_1.default.isPlainObject(value) ? new Updux(value) : value)(fp_1.default.getOr({}, 'subduxes', config));
|
2019-11-05 01:34:14 +00:00
|
|
|
this.localActions = fp_1.default.getOr({}, 'actions', config);
|
|
|
|
this.localEffects = fp_1.default.getOr({}, 'effects', config);
|
2019-10-24 15:52:36 +00:00
|
|
|
this.initial = buildInitial_1.default(config.initial, fp_1.default.mapValues(({ initial }) => initial)(this.subduxes));
|
2019-11-05 01:34:14 +00:00
|
|
|
this.localMutations = fp_1.default.mapValues((m) => this.groomMutations(m))(fp_1.default.getOr({}, 'mutations', config));
|
|
|
|
}
|
|
|
|
get middleware() {
|
2019-11-07 00:07:06 +00:00
|
|
|
return buildMiddleware_1.default(this.localEffects, this.actions, this.subduxes);
|
2019-11-05 01:34:14 +00:00
|
|
|
}
|
|
|
|
get actions() {
|
|
|
|
return buildActions_1.default(this.localActions, [...Object.keys(this.localMutations), ...Object.keys(this.localEffects)], fp_1.default.flatten(Object.values(this.subduxes).map(({ actions }) => Object.entries(actions))));
|
|
|
|
}
|
|
|
|
get upreducer() {
|
|
|
|
return buildUpreducer_1.default(this.initial, this.mutations);
|
|
|
|
}
|
|
|
|
get reducer() {
|
|
|
|
return (state, action) => this.upreducer(action)(state);
|
|
|
|
}
|
|
|
|
get mutations() {
|
|
|
|
return buildMutations_1.default(this.localMutations, this.subduxes);
|
|
|
|
}
|
2019-11-06 00:47:27 +00:00
|
|
|
get subduxUpreducer() {
|
|
|
|
return buildUpreducer_1.default(this.initial, buildMutations_1.default({}, this.subduxes));
|
|
|
|
}
|
2019-11-05 01:34:14 +00:00
|
|
|
get createStore() {
|
2019-10-24 15:52:36 +00:00
|
|
|
const actions = this.actions;
|
2019-11-05 01:34:14 +00:00
|
|
|
return buildCreateStore_1.default(this.reducer, this.initial, this.middleware, this.actions);
|
|
|
|
}
|
|
|
|
get asDux() {
|
|
|
|
return {
|
|
|
|
createStore: this.createStore,
|
|
|
|
upreducer: this.upreducer,
|
|
|
|
subduxes: this.subduxes,
|
|
|
|
middleware: this.middleware,
|
|
|
|
actions: this.actions,
|
|
|
|
reducer: this.reducer,
|
|
|
|
mutations: this.mutations,
|
|
|
|
initial: this.initial,
|
|
|
|
};
|
|
|
|
}
|
2019-11-06 00:47:27 +00:00
|
|
|
addMutation(creator, mutation, isSink) {
|
2019-11-05 01:34:14 +00:00
|
|
|
this.localActions[creator.type] = creator;
|
2019-11-06 00:47:27 +00:00
|
|
|
this.localMutations[creator.type] = [
|
|
|
|
this.groomMutations(mutation),
|
|
|
|
isSink,
|
|
|
|
];
|
2019-10-24 15:52:36 +00:00
|
|
|
}
|
2019-10-22 22:15:08 +00:00
|
|
|
}
|
2019-11-05 01:34:14 +00:00
|
|
|
__decorate([
|
|
|
|
mobx_1.observable
|
|
|
|
], Updux.prototype, "localEffects", void 0);
|
|
|
|
__decorate([
|
|
|
|
mobx_1.observable
|
|
|
|
], Updux.prototype, "localActions", void 0);
|
|
|
|
__decorate([
|
|
|
|
mobx_1.observable
|
|
|
|
], Updux.prototype, "localMutations", void 0);
|
|
|
|
__decorate([
|
|
|
|
mobx_1.computed
|
|
|
|
], Updux.prototype, "middleware", null);
|
|
|
|
__decorate([
|
|
|
|
mobx_1.computed
|
|
|
|
], Updux.prototype, "actions", null);
|
|
|
|
__decorate([
|
|
|
|
mobx_1.computed
|
|
|
|
], Updux.prototype, "upreducer", null);
|
|
|
|
__decorate([
|
|
|
|
mobx_1.computed
|
|
|
|
], Updux.prototype, "reducer", null);
|
|
|
|
__decorate([
|
|
|
|
mobx_1.computed
|
|
|
|
], Updux.prototype, "mutations", null);
|
2019-11-06 00:47:27 +00:00
|
|
|
__decorate([
|
|
|
|
mobx_1.computed
|
|
|
|
], Updux.prototype, "subduxUpreducer", null);
|
2019-11-05 01:34:14 +00:00
|
|
|
__decorate([
|
|
|
|
mobx_1.computed
|
|
|
|
], Updux.prototype, "createStore", null);
|
2019-10-22 22:15:08 +00:00
|
|
|
exports.Updux = Updux;
|
2019-10-24 15:52:36 +00:00
|
|
|
exports.default = Updux;
|
|
|
|
//# sourceMappingURL=updux.js.map
|