UNPKG

1.07 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const action_1 = require("../action");
4const virtual_store_1 = require("../virtual-store");
5class PromiseQueue extends virtual_store_1.VirtualStore {
6}
7exports.PromiseQueue = PromiseQueue;
8class PromiseAction extends action_1.ReduxAction {
9}
10exports.PromiseAction = PromiseAction;
11function promiseMiddleware(store) {
12 return (next) => {
13 return (action) => {
14 if (!PromiseAction.is(action)) {
15 return next(action);
16 }
17 const { promise, success, failed } = action.payload;
18 promise.then((data) => {
19 store.dispatch(new success(data).toJSON());
20 }, (e) => {
21 store.dispatch(new failed(e).toJSON());
22 });
23 };
24 };
25}
26exports.promiseMiddleware = promiseMiddleware;
27class PromisePlugin {
28 __redux_plugin(redux) {
29 redux.use(promiseMiddleware);
30 redux.register(PromiseQueue);
31 }
32}
33exports.PromisePlugin = PromisePlugin;
34//# sourceMappingURL=promise.js.map
\No newline at end of file