Skip to content

Commit b406ef7

Browse files
committed
tnx olegman
1 parent 4a76da6 commit b406ef7

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
node_modules
33
dev_modules
44
*.log
5-
lib
6-
typings
5+
typings

lib/index.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"use strict";
2+
var __assign = (this && this.__assign) || Object.assign || function(t) {
3+
for (var s, i = 1, n = arguments.length; i < n; i++) {
4+
s = arguments[i];
5+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6+
t[p] = s[p];
7+
}
8+
return t;
9+
};
10+
var redux_actions_helpers_1 = require("redux-actions-helpers");
11+
// actions
12+
exports.start = redux_actions_helpers_1.createAction('@@router/START', function (payload) { return ({ payload: payload }); });
13+
exports.end = redux_actions_helpers_1.createAction('@@router/END', function (payload) { return ({ payload: payload }); });
14+
exports.error = redux_actions_helpers_1.createAction('@@router/ERROR', function (payload) { return ({ payload: payload }); });
15+
// export const cancel = createAction('@@router/CANCEL');
16+
// reducer
17+
var initialState = {
18+
path: null,
19+
location: null,
20+
route: null,
21+
status: null,
22+
params: {},
23+
redirect: null,
24+
error: null,
25+
isTransition: false,
26+
ctx: {}
27+
};
28+
exports.reducer = redux_actions_helpers_1.handleActions((_a = {},
29+
_a[exports.start + exports.end + exports.error] = function (state, _a) {
30+
var payload = _a.payload;
31+
return __assign({}, state, payload);
32+
} /*,
33+
[cancel]: () => {
34+
return initialState;
35+
}*/,
36+
_a), { initialState: initialState });
37+
// hook
38+
exports.hookRedux = function (_a) {
39+
var dispatch = _a.dispatch, server = _a.server;
40+
return ({
41+
start: function (_a) {
42+
var path = _a.path, location = _a.location, ctx = _a.ctx;
43+
var plainCtx = ctx.toObject();
44+
dispatch(exports.start({ path: path, location: location, isTransition: true, ctx: plainCtx }));
45+
},
46+
resolve: function (_a) {
47+
var route = _a.route, status = _a.status, params = _a.params, redirect = _a.redirect, ctx = _a.ctx;
48+
var plainCtx = ctx.toObject();
49+
server && dispatch(exports.end({ route: route, status: status, params: params, redirect: redirect, isTransition: false, ctx: plainCtx }));
50+
},
51+
render: function (_a) {
52+
var route = _a.route, status = _a.status, params = _a.params, redirect = _a.redirect, ctx = _a.ctx;
53+
var plainCtx = ctx.toObject();
54+
dispatch(exports.end({ route: route, status: status, params: params, redirect: redirect, isTransition: false, ctx: plainCtx }));
55+
},
56+
error: function (_a) {
57+
var err = _a.error, ctx = _a.ctx;
58+
var plainCtx = ctx.toObject();
59+
dispatch(exports.error({ error: err, isTransition: false, ctx: plainCtx }));
60+
},
61+
cancel: function () {
62+
console.warn('router cancel transition');
63+
// dispatch(cancel());
64+
}
65+
});
66+
};
67+
var _a;

0 commit comments

Comments
 (0)