1 |
|
2 |
|
3 |
|
4 |
|
5 | 'use strict';
|
6 |
|
7 | Object.defineProperty(exports, '__esModule', {
|
8 | value: true
|
9 | });
|
10 |
|
11 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
12 |
|
13 | var _componentCookie = require('component-cookie');
|
14 |
|
15 | var _componentCookie2 = _interopRequireDefault(_componentCookie);
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | function cookieMiddleware(cookieMap) {
|
22 | var cookie = cookieMap ? map(cookieMap) : _componentCookie2['default'];
|
23 |
|
24 | return function (_ref) {
|
25 | var dispatch = _ref.dispatch;
|
26 | var getState = _ref.getState;
|
27 | return function (next) {
|
28 | return function (action) {
|
29 | return action.type === 'GET_COOKIE' || action.type === 'SET_COOKIE' ? Promise.resolve(handle(cookie, action)) : next(action);
|
30 | };
|
31 | };
|
32 | };
|
33 | }
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | function handle(cookie, action) {
|
40 | var _action$payload = action.payload;
|
41 | var name = _action$payload.name;
|
42 | var value = _action$payload.value;
|
43 | var opts = _action$payload.opts;
|
44 |
|
45 | switch (action.type) {
|
46 | case 'SET_COOKIE':
|
47 | return cookie(name, value, opts);
|
48 | case 'GET_COOKIE':
|
49 | return cookie(name);
|
50 | }
|
51 | }
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | function map(cookieMap) {
|
59 | return function (name, value) {
|
60 | if (arguments.length === 2) {
|
61 | cookieMap[name] = value;
|
62 | }
|
63 |
|
64 | return cookieMap[name];
|
65 | };
|
66 | }
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | exports['default'] = cookieMiddleware;
|
73 | module.exports = exports['default']; |
\ | No newline at end of file |