@thoughtbot/superglue 0.53.3 → 0.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js DELETED
@@ -1,265 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.updateFragments = exports.superglueReducer = exports.pageReducer = exports.mapDispatchToPropsIncludingVisitAndRemote = exports.getIn = exports.fragmentMiddleware = exports.UPDATE_FRAGMENTS = exports.SAVE_RESPONSE = exports.REMOVE_PAGE = exports.GRAFTING_SUCCESS = exports.GRAFTING_ERROR = exports.COPY_PAGE = exports.BEFORE_VISIT = exports.BEFORE_REMOTE = exports.BEFORE_FETCH = exports.ApplicationBase = void 0;
5
-
6
- var _react = _interopRequireDefault(require("react"));
7
-
8
- var _urlParse = _interopRequireDefault(require("url-parse"));
9
-
10
- var _reducers = require("./reducers");
11
-
12
- exports.rootReducer = _reducers.rootReducer;
13
- exports.superglueReducer = _reducers.superglueReducer;
14
- exports.pageReducer = _reducers.pageReducer;
15
- exports.updateFragments = _reducers.updateFragments;
16
-
17
- var _config = require("./config");
18
-
19
- var _utils = require("./utils");
20
-
21
- exports.urlToPageKey = _utils.urlToPageKey;
22
-
23
- var _action_creators = require("./action_creators");
24
-
25
- var _actions = require("./actions");
26
-
27
- exports.HISTORY_CHANGE = _actions.HISTORY_CHANGE;
28
- exports.BEFORE_FETCH = _actions.BEFORE_FETCH;
29
- exports.BEFORE_VISIT = _actions.BEFORE_VISIT;
30
- exports.BEFORE_REMOTE = _actions.BEFORE_REMOTE;
31
- exports.SAVE_RESPONSE = _actions.SAVE_RESPONSE;
32
- exports.UPDATE_FRAGMENTS = _actions.UPDATE_FRAGMENTS;
33
- exports.COPY_PAGE = _actions.COPY_PAGE;
34
- exports.REMOVE_PAGE = _actions.REMOVE_PAGE;
35
- exports.GRAFTING_ERROR = _actions.GRAFTING_ERROR;
36
- exports.GRAFTING_SUCCESS = _actions.GRAFTING_SUCCESS;
37
-
38
- var _redux = require("redux");
39
-
40
- var _reduxThunk = _interopRequireDefault(require("redux-thunk"));
41
-
42
- var _reactRedux = require("react-redux");
43
-
44
- var _history = require("history");
45
-
46
- var _Nav = _interopRequireDefault(require("./components/Nav"));
47
-
48
- var _react2 = require("./utils/react");
49
-
50
- exports.mapStateToProps = _react2.mapStateToProps;
51
- exports.mapDispatchToProps = _react2.mapDispatchToProps;
52
- exports.mapDispatchToPropsIncludingVisitAndRemote = _react2.mapDispatchToPropsIncludingVisitAndRemote;
53
-
54
- var _middleware = require("./middleware");
55
-
56
- exports.fragmentMiddleware = _middleware.fragmentMiddleware;
57
-
58
- var _immutability = require("./utils/immutability");
59
-
60
- exports.getIn = _immutability.getIn;
61
-
62
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
63
-
64
- function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
65
-
66
- function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
67
-
68
- function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
69
-
70
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
71
-
72
- function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
73
-
74
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
75
-
76
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
77
-
78
- function pageToInitialState(key, page) {
79
- var _pages;
80
-
81
- var slices = page.slices || {};
82
- return Object.assign({
83
- pages: (_pages = {}, _pages[key] = page, _pages)
84
- }, slices);
85
- }
86
-
87
- function start(_ref) {
88
- var initialPage = _ref.initialPage,
89
- _ref$baseUrl = _ref.baseUrl,
90
- baseUrl = _ref$baseUrl === void 0 ? _config.config.baseUrl : _ref$baseUrl,
91
- _ref$maxPages = _ref.maxPages,
92
- maxPages = _ref$maxPages === void 0 ? _config.config.maxPages : _ref$maxPages,
93
- path = _ref.path;
94
- var initialPageKey = (0, _utils.urlToPageKey)((0, _urlParse["default"])(path).href);
95
- var csrfToken = initialPage.csrfToken;
96
- var location = (0, _urlParse["default"])(path);
97
- _config.config.baseUrl = baseUrl;
98
- _config.config.maxPages = maxPages;
99
- return {
100
- reducer: _reducers.rootReducer,
101
- prepareStore: function prepareStore(store) {
102
- store.dispatch({
103
- type: _actions.HISTORY_CHANGE,
104
- payload: {
105
- pathname: location.pathname,
106
- search: location.query,
107
- hash: location.hash
108
- }
109
- });
110
- store.dispatch((0, _action_creators.saveAndProcessPage)(initialPageKey, initialPage));
111
- store.dispatch({
112
- type: _actions.SET_CSRF_TOKEN,
113
- payload: {
114
- csrfToken: csrfToken
115
- }
116
- });
117
- },
118
- initialState: pageToInitialState(initialPageKey, initialPage),
119
- initialPageKey: initialPageKey
120
- };
121
- }
122
-
123
- var NotImplementedError = /*#__PURE__*/function (_Error) {
124
- _inheritsLoose(NotImplementedError, _Error);
125
-
126
- function NotImplementedError(message) {
127
- var _this;
128
-
129
- _this = _Error.call(this, message) || this;
130
- _this.name = _this.constructor.name;
131
- return _this;
132
- }
133
-
134
- return NotImplementedError;
135
- }( /*#__PURE__*/_wrapNativeSuper(Error));
136
-
137
- var ApplicationBase = exports.ApplicationBase = /*#__PURE__*/function (_React$Component) {
138
- _inheritsLoose(ApplicationBase, _React$Component);
139
-
140
- function ApplicationBase(props) {
141
- var _this2$history;
142
-
143
- var _this2;
144
-
145
- _this2 = _React$Component.call(this, props) || this;
146
- _this2.hasWindow = typeof window !== 'undefined'; // Create a navigator Ref for UJS attributes and to enhance the base `visit`
147
- // and `visit` thunks
148
-
149
- _this2.navigatorRef = /*#__PURE__*/_react["default"].createRef(); // Retrieve initial values and methods to prepare the store.
150
-
151
- var _start = start({
152
- initialPage: _this2.props.initialPage,
153
- baseUrl: _this2.props.baseUrl,
154
- path: _this2.props.path // The max number of pages to keep in the store. Default is 20
155
- // maxPages: 20
156
-
157
- }),
158
- prepareStore = _start.prepareStore,
159
- initialState = _start.initialState,
160
- initialPageKey = _start.initialPageKey,
161
- reducer = _start.reducer;
162
-
163
- _this2.initialPageKey = initialPageKey; // Build the store and pass Superglue's provided reducer to be combined with
164
- // your reducers located at `application_reducer.js`
165
-
166
- _this2.store = _this2.buildStore(initialState, reducer); // Fire initial events and populate the store
167
-
168
- prepareStore(_this2.store); // Build history
169
-
170
- _this2.history = _this2.createHistory();
171
-
172
- (_this2$history = _this2.history).replace.apply(_this2$history, (0, _utils.argsForHistory)(_this2.props.path));
173
-
174
- var nextMapping = Object.assign({}, _this2.mapping());
175
-
176
- for (var key in nextMapping) {
177
- var component = nextMapping[key];
178
- nextMapping[key] = (0, _reactRedux.connect)(_react2.mapStateToProps, _react2.mapDispatchToProps)(component);
179
- }
180
-
181
- _this2.connectedMapping = nextMapping; // Build visit and remote thunks
182
- // Your modified `visit` and `remote` will get passed below to the
183
- // Nav component then to your components
184
- //
185
- // You can access them via `this.props.visit` or `this.props.remote`. In
186
- // your page components
187
-
188
- var _this2$visitAndRemote = _this2.visitAndRemote(_this2.navigatorRef, _this2.store),
189
- visit = _this2$visitAndRemote.visit,
190
- remote = _this2$visitAndRemote.remote;
191
-
192
- _this2.visit = visit;
193
- _this2.remote = remote;
194
- return _this2;
195
- }
196
-
197
- var _proto = ApplicationBase.prototype;
198
-
199
- _proto.visitAndRemote = function visitAndRemote() {
200
- throw new NotImplementedError('Implement this');
201
- };
202
-
203
- _proto.componentDidMount = function componentDidMount() {
204
- var appEl = this.props.appEl; // Create the ujs event handlers. You can change the ujsAttributePrefix
205
- // in the event the data attribute conflicts with another.
206
-
207
- this.ujsHandlers = (0, _utils.ujsHandlers)({
208
- visit: this.visit,
209
- remote: this.remote,
210
- store: this.store,
211
- ujsAttributePrefix: 'data-sg'
212
- });
213
- var _this$ujsHandlers = this.ujsHandlers,
214
- onClick = _this$ujsHandlers.onClick,
215
- onSubmit = _this$ujsHandlers.onSubmit;
216
- appEl.addEventListener('click', onClick);
217
- appEl.addEventListener('submit', onSubmit);
218
- };
219
-
220
- _proto.componentWillUnmount = function componentWillUnmount() {
221
- var appEl = this.props.appEl;
222
- var _this$ujsHandlers2 = this.ujsHandlers,
223
- onClick = _this$ujsHandlers2.onClick,
224
- onSubmit = _this$ujsHandlers2.onSubmit;
225
- appEl.removeEventListener('click', onClick);
226
- appEl.removeEventListener('submit', onSubmit);
227
- };
228
-
229
- _proto.buildStore = function buildStore(initialState, reducer) {
230
- var store = (0, _redux.createStore)((0, _redux.combineReducers)(reducer), initialState, (0, _redux.compose)((0, _redux.applyMiddleware)(_reduxThunk["default"])));
231
- return store;
232
- };
233
-
234
- _proto.createHistory = function createHistory() {
235
- if (this.hasWindow) {
236
- // This is used for client side rendering
237
- return (0, _history.createBrowserHistory)({});
238
- } else {
239
- // This is used for server side rendering
240
- return (0, _history.createMemoryHistory)({});
241
- }
242
- };
243
-
244
- _proto.mapping = function mapping() {
245
- throw new NotImplementedError('Implement this');
246
- };
247
-
248
- _proto.render = function render() {
249
- // The Nav component is pretty bare and can be inherited from for custom
250
- // behavior or replaced with your own.
251
- return /*#__PURE__*/_react["default"].createElement(_reactRedux.Provider, {
252
- store: this.store
253
- }, /*#__PURE__*/_react["default"].createElement(_Nav["default"], {
254
- store: this.store,
255
- ref: this.navigatorRef,
256
- visit: this.visit,
257
- remote: this.remote,
258
- mapping: this.connectedMapping,
259
- history: this.history,
260
- initialPageKey: this.initialPageKey
261
- }));
262
- };
263
-
264
- return ApplicationBase;
265
- }(_react["default"].Component);
package/middleware.js DELETED
@@ -1,78 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.fragmentMiddleware = void 0;
5
-
6
- var actions = _interopRequireWildcard(require("./actions"));
7
-
8
- var _immutability = require("./utils/immutability");
9
-
10
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
-
12
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
-
14
- var actionValues = Object.values(actions);
15
-
16
- var fragmentMiddleware = exports.fragmentMiddleware = function fragmentMiddleware(store) {
17
- return function (next) {
18
- return function (action) {
19
- var prevState = store.getState();
20
- var nextAction = next(action);
21
- var nextState = store.getState();
22
-
23
- if (actionValues.includes(action.type)) {
24
- return nextAction;
25
- }
26
-
27
- if (prevState.pages === nextState.pages) {
28
- return nextAction;
29
- }
30
-
31
- var changedFragments = {};
32
- var changedKeys = Object.keys(nextState.pages).filter(function (key) {
33
- return prevState.pages[key] !== nextState.pages[key];
34
- });
35
-
36
- if (changedKeys.length === 0) {
37
- return nextAction;
38
- }
39
-
40
- changedKeys.forEach(function (key) {
41
- nextState.pages[key].fragments.forEach(function (fragment) {
42
- var type = fragment.type,
43
- path = fragment.path;
44
- var nextPage = nextState.pages[key];
45
- var prevPage = prevState.pages[key];
46
- var nextFragment, prevFragment;
47
-
48
- try {
49
- prevFragment = (0, _immutability.getIn)(prevPage, path);
50
- nextFragment = (0, _immutability.getIn)(nextPage, path);
51
- } catch (err) {
52
- if (err.name == 'KeyPathError') {
53
- console.warn(err.message);
54
- } else {
55
- throw err;
56
- }
57
- }
58
-
59
- if (nextFragment !== undefined && prevFragment !== undefined && nextFragment !== prevFragment && nextFragment) {
60
- changedFragments[type] = nextFragment;
61
- }
62
- });
63
- });
64
-
65
- if (Object.keys(changedFragments).length === 0) {
66
- return nextAction;
67
- }
68
-
69
- store.dispatch({
70
- type: actions.UPDATE_FRAGMENTS,
71
- payload: {
72
- changedFragments: changedFragments
73
- }
74
- });
75
- return nextAction;
76
- };
77
- };
78
- };
package/reducers/index.js DELETED
@@ -1,263 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.appendReceivedFragmentsOntoPage = appendReceivedFragmentsOntoPage;
5
- exports.graftNodeOntoPage = graftNodeOntoPage;
6
- exports.handleGraft = handleGraft;
7
- exports.metaReducer = metaReducer;
8
- exports.pageReducer = pageReducer;
9
- exports.rootReducer = void 0;
10
- exports.superglueReducer = superglueReducer;
11
-
12
- var _utils = require("../utils");
13
-
14
- var _actions = require("../actions");
15
-
16
- var _config = require("../config");
17
-
18
- function addPlaceholdersToDeferredNodes(existingPage, page) {
19
- var _existingPage$defers = existingPage.defers,
20
- defers = _existingPage$defers === void 0 ? [] : _existingPage$defers;
21
- var prevDefers = defers.map(function (_ref) {
22
- var path = _ref.path;
23
- var node = (0, _utils.getIn)(existingPage, path);
24
- var copy = JSON.stringify(node);
25
- return [path, JSON.parse(copy)];
26
- });
27
- return prevDefers.reduce(function (memo, _ref2) {
28
- var path = _ref2[0],
29
- node = _ref2[1];
30
- return (0, _utils.setIn)(page, path, node);
31
- }, page);
32
- }
33
-
34
- function constrainPagesSize(state) {
35
- var maxPages = _config.config.maxPages;
36
- var allPageKeys = Object.keys(state);
37
- var cacheTimesRecentFirst = allPageKeys.map(function (key) {
38
- return state[key].savedAt;
39
- }).sort(function (a, b) {
40
- return b - a;
41
- });
42
-
43
- for (var _i = 0, _Array$from = Array.from(allPageKeys); _i < _Array$from.length; _i++) {
44
- var key = _Array$from[_i];
45
-
46
- if (state[key].savedAt <= cacheTimesRecentFirst[maxPages - 1]) {
47
- delete state[key];
48
- }
49
- }
50
- }
51
-
52
- function saveResponse(state, pageKey, page) {
53
- state = Object.assign({}, state);
54
- page = Object.assign({
55
- pageKey: pageKey,
56
- fragments: []
57
- }, page, {
58
- savedAt: Date.now()
59
- });
60
- var existingPage = state[pageKey];
61
-
62
- if (existingPage) {
63
- page = addPlaceholdersToDeferredNodes(existingPage, page);
64
- }
65
-
66
- constrainPagesSize(state);
67
- state[pageKey] = page;
68
- return state;
69
- }
70
-
71
- function appendReceivedFragmentsOntoPage(state, pageKey, receivedFragments) {
72
- if (!pageKey) {
73
- return state;
74
- }
75
-
76
- if (receivedFragments.length === 0) {
77
- return state;
78
- }
79
-
80
- var currentPage = state[pageKey];
81
- var _currentPage$fragment = currentPage.fragments,
82
- prevFragments = _currentPage$fragment === void 0 ? [] : _currentPage$fragment;
83
- var nextFragments = [].concat(prevFragments);
84
- var existingKeys = {};
85
- prevFragments.forEach(function (frag) {
86
- return existingKeys[frag.path] = true;
87
- });
88
- receivedFragments.forEach(function (frag) {
89
- if (!existingKeys[frag.path]) {
90
- nextFragments.push(frag);
91
- }
92
- });
93
- var nextPage = Object.assign({}, currentPage, {
94
- fragments: nextFragments
95
- });
96
- var nextState = Object.assign({}, state);
97
- nextState[pageKey] = nextPage;
98
- return nextState;
99
- }
100
-
101
- function graftNodeOntoPage(state, pageKey, node, pathToNode) {
102
- if (!node) {
103
- console.warn('There was no node returned in the response. Do you have the correct key path in your props_at?');
104
- return state;
105
- }
106
-
107
- if (!pathToNode || !pageKey) {
108
- return state;
109
- }
110
-
111
- var fullPathToNode = [pageKey, pathToNode].join('.');
112
- return (0, _utils.setIn)(state, fullPathToNode, node);
113
- }
114
-
115
- function handleGraft(state, pageKey, page) {
116
- var currentPage = state[pageKey];
117
-
118
- if (!currentPage) {
119
- var error = new Error("Superglue was looking for " + pageKey + " in your state, but could not find it in your mapping. Did you forget to pass in a valid pageKey to this.props.remote or this.props.visit?");
120
- throw error;
121
- }
122
-
123
- var receivedNode = page.data,
124
- pathToNode = page.path,
125
- _page$fragments = page.fragments,
126
- receivedFragments = _page$fragments === void 0 ? [] : _page$fragments;
127
- return [function (nextState) {
128
- return graftNodeOntoPage(nextState, pageKey, receivedNode, pathToNode);
129
- }, function (nextState) {
130
- return appendReceivedFragmentsOntoPage(nextState, pageKey, receivedFragments);
131
- }].reduce(function (memo, fn) {
132
- return fn(memo);
133
- }, state);
134
- }
135
-
136
- function pageReducer(state, action) {
137
- if (state === void 0) {
138
- state = {};
139
- }
140
-
141
- switch (action.type) {
142
- case _actions.SAVE_RESPONSE:
143
- {
144
- var _action$payload = action.payload,
145
- pageKey = _action$payload.pageKey,
146
- page = _action$payload.page;
147
- return saveResponse(state, pageKey, page);
148
- }
149
-
150
- case _actions.HANDLE_GRAFT:
151
- {
152
- var _action$payload2 = action.payload,
153
- _pageKey = _action$payload2.pageKey,
154
- _page = _action$payload2.page;
155
- return handleGraft(state, _pageKey, _page);
156
- }
157
-
158
- case _actions.UPDATE_FRAGMENTS:
159
- {
160
- var changedFragments = action.payload.changedFragments;
161
- var nextState = state;
162
- Object.entries(state).forEach(function (_ref3) {
163
- var pageKey = _ref3[0],
164
- page = _ref3[1];
165
- page.fragments.forEach(function (fragment) {
166
- var type = fragment.type,
167
- path = fragment.path;
168
- var changedNode = changedFragments[type];
169
- var currentNode = (0, _utils.getIn)(nextState, pageKey + "." + path);
170
-
171
- if (type in changedFragments && changedNode !== currentNode) {
172
- var nextNode = JSON.parse(JSON.stringify(changedNode));
173
- nextState = (0, _utils.setIn)(nextState, pageKey + "." + path, nextNode);
174
- }
175
- });
176
- });
177
- return nextState;
178
- }
179
-
180
- case _actions.COPY_PAGE:
181
- {
182
- var _nextState = Object.assign({}, state);
183
-
184
- var _action$payload3 = action.payload,
185
- from = _action$payload3.from,
186
- to = _action$payload3.to;
187
- _nextState[(0, _utils.urlToPageKey)(to)] = JSON.parse(JSON.stringify(_nextState[from]));
188
- return _nextState;
189
- }
190
-
191
- case _actions.REMOVE_PAGE:
192
- {
193
- var _pageKey2 = action.payload.pageKey;
194
-
195
- var _nextState2 = Object.assign({}, state);
196
-
197
- delete _nextState2[_pageKey2];
198
- return _nextState2;
199
- }
200
-
201
- default:
202
- return state;
203
- }
204
- }
205
-
206
- function metaReducer(state, action) {
207
- if (state === void 0) {
208
- state = {};
209
- }
210
-
211
- switch (action.type) {
212
- case _actions.HISTORY_CHANGE:
213
- {
214
- var _action$payload4 = action.payload,
215
- pathname = _action$payload4.pathname,
216
- search = _action$payload4.search,
217
- hash = _action$payload4.hash;
218
- var currentPageKey = (0, _utils.urlToPageKey)(pathname + search);
219
- return Object.assign({}, state, {
220
- currentPageKey: currentPageKey,
221
- pathname: pathname,
222
- search: search,
223
- hash: hash
224
- });
225
- }
226
-
227
- case _actions.SAVE_RESPONSE:
228
- {
229
- var _action$payload$page = action.payload.page,
230
- csrfToken = _action$payload$page.csrfToken,
231
- assets = _action$payload$page.assets;
232
- return Object.assign({}, state, {
233
- csrfToken: csrfToken,
234
- assets: assets
235
- });
236
- }
237
-
238
- case _actions.SET_CSRF_TOKEN:
239
- {
240
- var _csrfToken = action.payload.csrfToken;
241
- return Object.assign({}, state, {
242
- csrfToken: _csrfToken
243
- });
244
- }
245
-
246
- default:
247
- return state;
248
- }
249
- }
250
-
251
- function superglueReducer(state, action) {
252
- if (state === void 0) {
253
- state = {};
254
- }
255
-
256
- var meta = metaReducer(state, action);
257
- return Object.assign({}, meta);
258
- }
259
-
260
- var rootReducer = exports.rootReducer = {
261
- superglue: superglueReducer,
262
- pages: pageReducer
263
- };
package/utils/helpers.js DELETED
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.argsForHistory = argsForHistory;
5
- exports.extractNodeAndPath = extractNodeAndPath;
6
- exports.isGraft = isGraft;
7
-
8
- var _url = require("./url");
9
-
10
- function isGraft(page) {
11
- return page.action === 'graft';
12
- }
13
-
14
- function extractNodeAndPath(page) {
15
- var node = page.data,
16
- action = page.action,
17
- pathToNode = page.path;
18
-
19
- if (action === 'graft') {
20
- return {
21
- node: node,
22
- pathToNode: pathToNode
23
- };
24
- } else {
25
- var errMsg = 'Expected page to be a graft response rendered from node filtering.';
26
- throw new Error(errMsg);
27
- }
28
- }
29
-
30
- function argsForHistory(path) {
31
- var pageKey = (0, _url.urlToPageKey)(path);
32
- return [path, {
33
- superglue: true,
34
- pageKey: pageKey,
35
- posX: 0,
36
- posY: 0
37
- }];
38
- }