1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const action_1 = require("../action");
|
4 | const virtual_store_1 = require("../virtual-store");
|
5 | class PromiseQueue extends virtual_store_1.VirtualStore {
|
6 | }
|
7 | exports.PromiseQueue = PromiseQueue;
|
8 | class PromiseAction extends action_1.ReduxAction {
|
9 | }
|
10 | exports.PromiseAction = PromiseAction;
|
11 | function 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 | }
|
26 | exports.promiseMiddleware = promiseMiddleware;
|
27 | class PromisePlugin {
|
28 | __redux_plugin(redux) {
|
29 | redux.use(promiseMiddleware);
|
30 | redux.register(PromiseQueue);
|
31 | }
|
32 | }
|
33 | exports.PromisePlugin = PromisePlugin;
|
34 |
|
\ | No newline at end of file |