UNPKG

redux-typed-kit

Version:

Powerful extensitions for building class-based Redux architecture powered by TypeScript.

44 lines 1.67 kB
import { createStore, applyMiddleware } from 'redux'; import { Middleware } from './middleware'; var Store = /** @class */ (function () { function Store(reducer) { var middlewares = []; for (var _i = 1; _i < arguments.length; _i++) { middlewares[_i - 1] = arguments[_i]; } this.p_reducer = reducer; this.p_middlewares = middlewares; } Store.prototype.getEnhancer = function () { var _this = this; return applyMiddleware.apply(void 0, this.p_middlewares.map(function (x) { return x instanceof Middleware ? x.create(_this) : x; })); }; Store.prototype.init = function () { this.p_store = createStore(this.p_reducer.create(), this.getEnhancer()); return this; }; Store.prototype.addMiddleware = function (middleware) { if (this.p_store != null) return; this.p_middlewares.push(middleware); }; Store.prototype.getMiddleware = function (type) { return this.p_middlewares.find(function (x) { return x instanceof Middleware && x.constructor.name == type; }); }; Store.prototype.subscribe = function (listener) { return this.p_store.subscribe(listener); }; Object.defineProperty(Store.prototype, "state", { get: function () { return this.p_store.getState(); }, enumerable: false, configurable: true }); Store.prototype.dispatch = function (action) { return this.p_store.dispatch(action.toPlainObject()); }; return Store; }()); export default Store; //# sourceMappingURL=store.js.map