@thoughtbot/superglue 0.50.0-beta1 → 0.51.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/.babelrc.js ADDED
@@ -0,0 +1,18 @@
1
+ module.exports = {
2
+ plugins: [
3
+ ["transform-react-remove-prop-types", {removeImport: true}]
4
+ ],
5
+ presets: [
6
+ [
7
+ "@babel/preset-env",
8
+ {
9
+ useBuiltIns: "entry",
10
+ corejs: "2",
11
+ loose: true,
12
+ }
13
+ ],
14
+ [
15
+ "@babel/preset-react"
16
+ ],
17
+ ],
18
+ };
package/.prettierrc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "semi": false,
3
+ "singleQuote": true,
4
+ "printWidth": 70,
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "semi": false,
3
+ "singleQuote": true,
4
+ "printWidth": 70
5
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016-2021 Johny Ho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -5,10 +5,11 @@ Use classic Rails to build rich React Redux applications with **NO APIs** and
5
5
 
6
6
  [![Build Status](https://circleci.com/gh/thoughtbot/superglue.svg?style=shield)](https://circleci.com/gh/thoughtbot/superglue)
7
7
 
8
- Superglue is a React Redux starter and library inspired by Turbolinks and designed
9
- to complement classic Rails. You can enjoy the benefits of Redux state
10
- management and React components without giving up the productivity of Rails form
11
- helpers, UJS, tag helpers, the flash, cookie auth, and more.
8
+ Superglue makes React and Redux equally as productive as Hotwire, Turbo and
9
+ Stimulus. Its inspired by Turbolinks and designed to feel like a natural
10
+ extension of Rails. Enjoy the benefits of Redux state management and React
11
+ components without giving up the productivity of Rails form helpers, UJS,
12
+ tag helpers, flash, cookie auth, and more.
12
13
 
13
14
  ## Caution
14
15
 
@@ -67,7 +68,6 @@ The above will request for `/posts` with an `accept` of `application/json`, and
67
68
  when the client receives the response, swap out the current component for the
68
69
  component the response asks for, and `pushState` on history.
69
70
 
70
-
71
71
  #### Partial updates
72
72
  Some features rely on updating some parts of the existing page. In
73
73
  addition to `data-sg-visit` and it's equivalent `this.props.visit`, Superglue
@@ -106,9 +106,8 @@ Documentation is hosted on [Github pages](https://thoughtbot.github.io/superglue
106
106
 
107
107
  ## Contributing
108
108
 
109
- See the [CONTRIBUTING] document. Thank you, [contributors]!
109
+ Thank you, [contributors]!
110
110
 
111
- [CONTRIBUTING]: CONTRIBUTING.md
112
111
  [contributors]: https://github.com/thoughtbot/superglue/graphs/contributors
113
112
 
114
113
  ## Special Thanks
@@ -118,5 +117,3 @@ Thanks to [jbuilder](https://github.com/rails/jbuilder),
118
117
  [turbolinks3](https://github.com/turbolinks/turbolinks-classic),
119
118
  [turbograft](https://github.com/Shopify/turbograft/),
120
119
  [turbostreamer](https://github.com/malomalo/turbostreamer)
121
-
122
-
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.clearFlash = clearFlash;
5
4
  exports.remote = remote;
6
5
  exports.visit = visit;
7
6
 
@@ -11,6 +10,20 @@ var _actions = require("../actions");
11
10
 
12
11
  var _index = require("./index");
13
12
 
13
+ function beforeVisit(payload) {
14
+ return {
15
+ type: _actions.BEFORE_VISIT,
16
+ payload: payload
17
+ };
18
+ }
19
+
20
+ function beforeRemote(payload) {
21
+ return {
22
+ type: _actions.BEFORE_REMOTE,
23
+ payload: payload
24
+ };
25
+ }
26
+
14
27
  function beforeFetch(payload) {
15
28
  return {
16
29
  type: _actions.BEFORE_FETCH,
@@ -46,28 +59,18 @@ function buildMeta(pageKey, page, state) {
46
59
  };
47
60
  }
48
61
 
49
- function clearFlash(_ref) {
50
- var pageKey = _ref.pageKey;
51
- return {
52
- type: _actions.CLEAR_FLASH,
53
- payload: {
54
- pageKey: pageKey
55
- }
56
- };
57
- }
58
-
59
62
  function remote(path, _temp) {
60
- var _ref2 = _temp === void 0 ? {} : _temp,
61
- _ref2$method = _ref2.method,
62
- method = _ref2$method === void 0 ? 'GET' : _ref2$method,
63
- headers = _ref2.headers,
64
- _ref2$body = _ref2.body,
65
- body = _ref2$body === void 0 ? '' : _ref2$body,
66
- pageKey = _ref2.pageKey,
67
- _ref2$beforeSave = _ref2.beforeSave,
68
- beforeSave = _ref2$beforeSave === void 0 ? function (prevPage, receivedPage) {
63
+ var _ref = _temp === void 0 ? {} : _temp,
64
+ _ref$method = _ref.method,
65
+ method = _ref$method === void 0 ? 'GET' : _ref$method,
66
+ headers = _ref.headers,
67
+ _ref$body = _ref.body,
68
+ body = _ref$body === void 0 ? '' : _ref$body,
69
+ pageKey = _ref.pageKey,
70
+ _ref$beforeSave = _ref.beforeSave,
71
+ beforeSave = _ref$beforeSave === void 0 ? function (prevPage, receivedPage) {
69
72
  return receivedPage;
70
- } : _ref2$beforeSave;
73
+ } : _ref$beforeSave;
71
74
 
72
75
  path = (0, _utils.withoutBusters)(path);
73
76
  pageKey = pageKey && (0, _utils.urlToPageKey)(pageKey);
@@ -78,12 +81,19 @@ function remote(path, _temp) {
78
81
  body: body
79
82
  });
80
83
  pageKey = pageKey || getState().superglue.currentPageKey;
84
+ var currentPageKey = getState().superglue.currentPageKey;
85
+ dispatch(beforeRemote({
86
+ currentPageKey: currentPageKey,
87
+ fetchArgs: fetchArgs
88
+ }));
81
89
  dispatch(beforeFetch({
82
90
  fetchArgs: fetchArgs
83
91
  }));
84
- return fetch.apply(void 0, fetchArgs).then(_utils.parseResponse).then(function (_ref3) {
85
- var rsp = _ref3.rsp,
86
- json = _ref3.json;
92
+ return fetch.apply(void 0, fetchArgs).then(_utils.parseResponse).then(function (_ref2) {
93
+ var _pages$currentPageKey;
94
+
95
+ var rsp = _ref2.rsp,
96
+ json = _ref2.json;
87
97
 
88
98
  var _getState = getState(),
89
99
  superglue = _getState.superglue,
@@ -95,6 +105,14 @@ function remote(path, _temp) {
95
105
  rsp: rsp,
96
106
  fetchArgs: fetchArgs
97
107
  });
108
+ var willReplaceCurrent = pageKey == currentPageKey;
109
+ var existingId = (_pages$currentPageKey = pages[currentPageKey]) == null ? void 0 : _pages$currentPageKey.componentIdentifier;
110
+ var receivedId = json.componentIdentifier;
111
+
112
+ if (willReplaceCurrent && !!existingId && existingId != receivedId) {
113
+ console.warn("You're about replace an existing page located at pages[\"" + currentPageKey + "\"]\nthat has the componentIdentifier \"" + existingId + "\" with the contents of a\nreceived page that has a componentIdentifier of \"" + receivedId + "\".\n\nThis can happen if you're using data-sg-remote or remote but your response\nredirected to a completely different page. Since remote requests do not\nnavigate or change the current page component, your current page component may\nreceive a shape that is unexpected and cause issues with rendering.\n\nConsider using data-sg-visit, the visit function, or redirect_back.");
114
+ }
115
+
98
116
  var page = beforeSave(pages[pageKey], json);
99
117
  return dispatch((0, _index.saveAndProcessPage)(pageKey, page)).then(function () {
100
118
  meta.pageKey = pageKey;
@@ -111,27 +129,23 @@ var lastVisitController = {
111
129
  };
112
130
 
113
131
  function visit(path, _temp2) {
114
- var _ref4 = _temp2 === void 0 ? {} : _temp2,
115
- _ref4$method = _ref4.method,
116
- method = _ref4$method === void 0 ? 'GET' : _ref4$method,
117
- headers = _ref4.headers,
118
- _ref4$body = _ref4.body,
119
- body = _ref4$body === void 0 ? '' : _ref4$body,
120
- placeholderKey = _ref4.placeholderKey,
121
- _ref4$beforeSave = _ref4.beforeSave,
122
- beforeSave = _ref4$beforeSave === void 0 ? function (prevPage, receivedPage) {
132
+ var _ref3 = _temp2 === void 0 ? {} : _temp2,
133
+ _ref3$method = _ref3.method,
134
+ method = _ref3$method === void 0 ? 'GET' : _ref3$method,
135
+ headers = _ref3.headers,
136
+ _ref3$body = _ref3.body,
137
+ body = _ref3$body === void 0 ? '' : _ref3$body,
138
+ placeholderKey = _ref3.placeholderKey,
139
+ _ref3$beforeSave = _ref3.beforeSave,
140
+ beforeSave = _ref3$beforeSave === void 0 ? function (prevPage, receivedPage) {
123
141
  return receivedPage;
124
- } : _ref4$beforeSave,
125
- _ref4$revisit = _ref4.revisit,
126
- revisit = _ref4$revisit === void 0 ? false : _ref4$revisit;
142
+ } : _ref3$beforeSave,
143
+ _ref3$revisit = _ref3.revisit,
144
+ revisit = _ref3$revisit === void 0 ? false : _ref3$revisit;
127
145
 
128
146
  path = (0, _utils.withoutBusters)(path);
129
147
  var pageKey = (0, _utils.urlToPageKey)(path);
130
148
  return function (dispatch, getState) {
131
- var currentKey = getState().superglue.currentPageKey;
132
- dispatch(clearFlash({
133
- pageKey: currentKey
134
- }));
135
149
  placeholderKey = placeholderKey && (0, _utils.urlToPageKey)(placeholderKey);
136
150
  var hasPlaceholder = !!getState().pages[placeholderKey];
137
151
 
@@ -160,14 +174,19 @@ function visit(path, _temp2) {
160
174
  method: method,
161
175
  signal: signal
162
176
  });
177
+ var currentPageKey = getState().superglue.currentPageKey;
178
+ dispatch(beforeVisit({
179
+ currentPageKey: currentPageKey,
180
+ fetchArgs: fetchArgs
181
+ }));
163
182
  dispatch(beforeFetch({
164
183
  fetchArgs: fetchArgs
165
184
  }));
166
185
  lastVisitController.abort();
167
186
  lastVisitController = controller;
168
- return fetch.apply(void 0, fetchArgs).then(_utils.parseResponse).then(function (_ref5) {
169
- var rsp = _ref5.rsp,
170
- json = _ref5.json;
187
+ return fetch.apply(void 0, fetchArgs).then(_utils.parseResponse).then(function (_ref4) {
188
+ var rsp = _ref4.rsp,
189
+ json = _ref4.json;
171
190
 
172
191
  var _getState2 = getState(),
173
192
  superglue = _getState2.superglue,
@@ -1,15 +1,17 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.UPDATE_FRAGMENTS = exports.SUPERGLUE_ERROR = exports.SET_CSRF_TOKEN = exports.SAVE_RESPONSE = exports.REMOVE_PAGE = exports.HISTORY_CHANGE = exports.HANDLE_GRAFT = exports.GRAFTING_SUCCESS = exports.GRAFTING_ERROR = exports.COPY_PAGE = exports.CLEAR_FLASH = exports.BEFORE_FETCH = void 0;
4
+ exports.UPDATE_FRAGMENTS = exports.SUPERGLUE_ERROR = exports.SET_CSRF_TOKEN = exports.SAVE_RESPONSE = exports.REMOVE_PAGE = exports.HISTORY_CHANGE = exports.HANDLE_GRAFT = exports.GRAFTING_SUCCESS = exports.GRAFTING_ERROR = exports.COPY_PAGE = exports.BEFORE_VISIT = exports.BEFORE_REMOTE = exports.BEFORE_FETCH = void 0;
5
5
  var BEFORE_FETCH = '@@superglue/BEFORE_FETCH';
6
6
  exports.BEFORE_FETCH = BEFORE_FETCH;
7
+ var BEFORE_VISIT = '@@superglue/BEFORE_VISIT';
8
+ exports.BEFORE_VISIT = BEFORE_VISIT;
9
+ var BEFORE_REMOTE = '@@superglue/BEFORE_REMOTE';
10
+ exports.BEFORE_REMOTE = BEFORE_REMOTE;
7
11
  var SAVE_RESPONSE = '@@superglue/SAVE_RESPONSE';
8
12
  exports.SAVE_RESPONSE = SAVE_RESPONSE;
9
13
  var HANDLE_GRAFT = '@@superglue/HANDLE_GRAFT';
10
14
  exports.HANDLE_GRAFT = HANDLE_GRAFT;
11
- var CLEAR_FLASH = '@@superglue/CLEAR_FLASH';
12
- exports.CLEAR_FLASH = CLEAR_FLASH;
13
15
  var SUPERGLUE_ERROR = '@@superglue/ERROR';
14
16
  exports.SUPERGLUE_ERROR = SUPERGLUE_ERROR;
15
17
  var GRAFTING_ERROR = '@@superglue/GRAFTING_ERROR';
@@ -222,7 +222,7 @@ var Nav = /*#__PURE__*/function (_React$Component) {
222
222
  var reminder = '';
223
223
 
224
224
  if (!identifier) {
225
- reminder = 'Did you forget to add `json.component_identifier` in your application.json.props layout?';
225
+ reminder = 'Did you forget to add `json.componentIdentifier` in your application.json.props layout?';
226
226
  }
227
227
 
228
228
  var error = new Error("Superglue Nav component was looking for " + identifier + " but could not find it in your mapping. " + reminder);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.updateFragments = exports.superglueReducer = exports.pageReducer = exports.mapDispatchToPropsIncludingVisitAndRemote = exports.getIn = exports.fragmentMiddleware = exports.ApplicationBase = void 0;
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
5
 
6
6
  var _react = _interopRequireDefault(require("react"));
7
7
 
@@ -24,6 +24,17 @@ var _action_creators = require("./action_creators");
24
24
 
25
25
  var _actions = require("./actions");
26
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
+
27
38
  var _redux = require("redux");
28
39
 
29
40
  var _reduxThunk = _interopRequireDefault(require("redux-thunk"));
@@ -67,9 +78,10 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
67
78
  function pageToInitialState(key, page) {
68
79
  var _pages;
69
80
 
70
- return {
81
+ var slices = page.slices || {};
82
+ return Object.assign({
71
83
  pages: (_pages = {}, _pages[key] = page, _pages)
72
- };
84
+ }, slices);
73
85
  }
74
86
 
75
87
  function start(_ref) {
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@thoughtbot/superglue",
3
+ "version": "0.51.0",
4
+ "description": "Use a vanilla Rails with React and Redux",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/thoughtbot/superglue.git"
8
+ },
9
+ "author": "Johny Ho",
10
+ "license": "MIT",
11
+ "bugs": {
12
+ "url": "https://github.com/thoughtbot/superglue/issues"
13
+ },
14
+ "homepage": "https://github.com/thoughtbot/superglue#readme",
15
+ "devDependencies": {
16
+ "@babel/cli": "^7.14.3",
17
+ "@babel/core": "^7.14.3",
18
+ "@babel/preset-env": "^7.14.4",
19
+ "@babel/preset-react": "^7.13.13",
20
+ "core-js": "^2.6.12",
21
+ "enzyme": "^3.11.0",
22
+ "enzyme-adapter-react-16": "^1.15.6",
23
+ "eslint": "^7.28.0",
24
+ "eslint-config-prettier": "^8.3.0",
25
+ "eslint-plugin-prettier": "^3.4.0",
26
+ "eslint-plugin-react": "^7.24.0",
27
+ "fetch-headers": "^2.0.0",
28
+ "fetch-mock": "^9.11.0",
29
+ "history": "^5.3.0",
30
+ "jest": "^27.0.4",
31
+ "node-fetch": "^2.6.1",
32
+ "prettier": "^2.3.1",
33
+ "prop-types": "^15.7.2",
34
+ "react": "^16.4.0",
35
+ "react-dom": "^16.4.0",
36
+ "react-redux": "^7.2.4",
37
+ "redux": "^4.1.0",
38
+ "redux-mock-store": "^1.5.4",
39
+ "redux-thunk": "^2.3.0"
40
+ },
41
+ "peerDependencies": {
42
+ "history": "^5.3.0",
43
+ "react": ">=16",
44
+ "react-redux": ">=7.2",
45
+ "redux": ">=4.1",
46
+ "redux-thunk": ">=2.3"
47
+ },
48
+ "dependencies": {
49
+ "abortcontroller-polyfill": "^1.7.3",
50
+ "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
51
+ "url-parse": "^1.5.1"
52
+ }
53
+ }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.addFlash = addFlash;
5
4
  exports.appendReceivedFragmentsOntoPage = appendReceivedFragmentsOntoPage;
6
5
  exports.graftNodeOntoPage = graftNodeOntoPage;
7
6
  exports.handleGraft = handleGraft;
@@ -99,14 +98,6 @@ function appendReceivedFragmentsOntoPage(state, pageKey, receivedFragments) {
99
98
  return nextState;
100
99
  }
101
100
 
102
- function addFlash(state, pageKey, receivedFlash) {
103
- var nextState = Object.assign({}, state);
104
- var nextPage = Object.assign({}, state[pageKey]);
105
- nextPage.flash = Object.assign({}, nextPage.flash, receivedFlash);
106
- nextState[pageKey] = nextPage;
107
- return nextState;
108
- }
109
-
110
101
  function graftNodeOntoPage(state, pageKey, node, pathToNode) {
111
102
  if (!node) {
112
103
  console.warn('There was no node returned in the response. Do you have the correct key path in your props_at?');
@@ -132,14 +123,11 @@ function handleGraft(state, pageKey, page) {
132
123
  var receivedNode = page.data,
133
124
  pathToNode = page.path,
134
125
  _page$fragments = page.fragments,
135
- receivedFragments = _page$fragments === void 0 ? [] : _page$fragments,
136
- receivedFlash = page.flash;
126
+ receivedFragments = _page$fragments === void 0 ? [] : _page$fragments;
137
127
  return [function (nextState) {
138
128
  return graftNodeOntoPage(nextState, pageKey, receivedNode, pathToNode);
139
129
  }, function (nextState) {
140
130
  return appendReceivedFragmentsOntoPage(nextState, pageKey, receivedFragments);
141
- }, function (nextState) {
142
- return addFlash(nextState, pageKey, receivedFlash);
143
131
  }].reduce(function (memo, fn) {
144
132
  return fn(memo);
145
133
  }, state);
@@ -189,37 +177,25 @@ function pageReducer(state, action) {
189
177
  return nextState;
190
178
  }
191
179
 
192
- case _actions.CLEAR_FLASH:
193
- {
194
- var _pageKey2 = action.payload.pageKey;
195
-
196
- var _nextState = Object.assign({}, state);
197
-
198
- var nextPage = Object.assign({}, state[_pageKey2]);
199
- nextPage.flash = {};
200
- _nextState[_pageKey2] = nextPage;
201
- return _nextState;
202
- }
203
-
204
180
  case _actions.COPY_PAGE:
205
181
  {
206
- var _nextState2 = Object.assign({}, state);
182
+ var _nextState = Object.assign({}, state);
207
183
 
208
184
  var _action$payload3 = action.payload,
209
185
  from = _action$payload3.from,
210
186
  to = _action$payload3.to;
211
- _nextState2[(0, _utils.urlToPageKey)(to)] = JSON.parse(JSON.stringify(_nextState2[from]));
212
- return _nextState2;
187
+ _nextState[(0, _utils.urlToPageKey)(to)] = JSON.parse(JSON.stringify(_nextState[from]));
188
+ return _nextState;
213
189
  }
214
190
 
215
191
  case _actions.REMOVE_PAGE:
216
192
  {
217
- var _pageKey3 = action.payload.pageKey;
193
+ var _pageKey2 = action.payload.pageKey;
218
194
 
219
- var _nextState3 = Object.assign({}, state);
195
+ var _nextState2 = Object.assign({}, state);
220
196
 
221
- delete _nextState3[_pageKey3];
222
- return _nextState3;
197
+ delete _nextState2[_pageKey2];
198
+ return _nextState2;
223
199
  }
224
200
 
225
201
  default:
@@ -23,17 +23,14 @@ function mapStateToProps(state, ownProps) {
23
23
 
24
24
  var _ref = state.pages[pageKey] || {
25
25
  data: {},
26
- flash: {},
27
26
  fragments: []
28
27
  },
29
28
  data = _ref.data,
30
- flash = _ref.flash,
31
29
  fragments = _ref.fragments;
32
30
 
33
31
  return Object.assign({}, data, params, {
34
32
  pageKey: pageKey,
35
33
  csrfToken: csrfToken,
36
- flash: flash,
37
34
  fragments: fragments
38
35
  });
39
36
  }
@@ -8,8 +8,7 @@ exports.pathQueryHash = pathQueryHash;
8
8
  exports.pathWithoutBZParams = pathWithoutBZParams;
9
9
  exports.removePropsAt = removePropsAt;
10
10
  exports.urlToPageKey = urlToPageKey;
11
- exports.withAntiCache = withAntiCache;
12
- exports.withMimeBust = withMimeBust;
11
+ exports.withFormatJson = withFormatJson;
13
12
  exports.withoutBusters = withoutBusters;
14
13
  exports.withoutHash = withoutHash;
15
14
 
@@ -17,10 +16,6 @@ var _urlParse = _interopRequireDefault(require("url-parse"));
17
16
 
18
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
18
 
20
- var uniqueId = function uniqueId() {
21
- return Math.random().toString(36).substring(2, 10);
22
- };
23
-
24
19
  function pathQuery(url) {
25
20
  var _parse = new _urlParse["default"](url, {}),
26
21
  pathname = _parse.pathname,
@@ -44,43 +39,17 @@ function hasPropsAt(url) {
44
39
  return !!query['props_at'];
45
40
  }
46
41
 
47
- function withAntiCache(url) {
48
- url = new _urlParse["default"](url, {}, true);
49
-
50
- if (Object.prototype.hasOwnProperty.call(url.query, '_')) {
51
- return url.toString();
52
- } else {
53
- url.query['_'] = uniqueId();
54
- return url.toString();
55
- }
56
- }
57
-
58
- function withMimeBust(url) {
42
+ function withFormatJson(url) {
59
43
  url = new _urlParse["default"](url, {}, true);
60
-
61
- if (Object.prototype.hasOwnProperty.call(url.query, '__')) {
62
- return url.toString();
63
- } else {
64
- url.query['__'] = '0';
65
- return url.toString();
66
- }
67
- }
68
-
69
- function withoutBusters(url) {
70
- url = new _urlParse["default"](url, {}, true);
71
- var query = url.query;
72
- delete query['__'];
73
- delete query['_'];
74
- url.query = query;
75
- return pathQuery(url.toString());
44
+ url.query['format'] = 'json';
45
+ return url.toString();
76
46
  }
77
47
 
78
48
  function pathWithoutBZParams(url) {
79
49
  url = new _urlParse["default"](url, {}, true);
80
50
  var query = url.query;
81
- delete query['__'];
82
- delete query['_'];
83
51
  delete query['props_at'];
52
+ delete query['format'];
84
53
  url.query = query;
85
54
  return pathQueryHash(url.toString());
86
55
  }
@@ -96,9 +65,8 @@ function removePropsAt(url) {
96
65
  function urlToPageKey(url) {
97
66
  url = new _urlParse["default"](url, {}, true);
98
67
  var query = url.query;
99
- delete query['__'];
100
- delete query['_'];
101
68
  delete query['props_at'];
69
+ delete query['format'];
102
70
  url.query = query;
103
71
  return pathQuery(url.toString());
104
72
  }
@@ -109,17 +77,16 @@ function withoutHash(url) {
109
77
  return url.toString();
110
78
  }
111
79
 
112
- function formatForXHR(url, opts) {
113
- if (opts === void 0) {
114
- opts = {};
115
- }
116
-
117
- var formats = [withMimeBust, withoutHash];
118
-
119
- if (opts.cacheRequest) {
120
- formats.push(withAntiCache);
121
- }
80
+ function withoutBusters(url) {
81
+ url = new _urlParse["default"](url, {}, true);
82
+ var query = url.query;
83
+ delete query['format'];
84
+ url.query = query;
85
+ return pathQuery(url.toString());
86
+ }
122
87
 
88
+ function formatForXHR(url) {
89
+ var formats = [withoutHash, withFormatJson];
123
90
  return formats.reduce(function (memo, f) {
124
91
  return f(memo);
125
92
  }, url);
package/package.json CHANGED
@@ -1,7 +1,17 @@
1
1
  {
2
2
  "name": "@thoughtbot/superglue",
3
- "version": "0.50.0-beta1",
3
+ "version": "0.51.0",
4
4
  "description": "Use a vanilla Rails with React and Redux",
5
+ "scripts": {
6
+ "test": "jest",
7
+ "lint": "eslint lib",
8
+ "clean": "rm -rf ./dist",
9
+ "copy:package": "cat ./package.json | jq 'del(.scripts)' > dist/package.json",
10
+ "copy:readme": "cp ../README.md dist/",
11
+ "build:index": "babel lib -d dist",
12
+ "build": "npm run clean && npm run build:index && npm run copy:package && npm run copy:readme",
13
+ "prepublishOnly": "npm run build"
14
+ },
5
15
  "repository": {
6
16
  "type": "git",
7
17
  "url": "git+https://github.com/thoughtbot/superglue.git"
Binary file
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes