@thoughtbot/superglue 0.50.0-beta1 → 0.50.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/README.md CHANGED
@@ -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,17 @@ 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 rsp = _ref2.rsp,
94
+ json = _ref2.json;
87
95
 
88
96
  var _getState = getState(),
89
97
  superglue = _getState.superglue,
@@ -111,27 +119,23 @@ var lastVisitController = {
111
119
  };
112
120
 
113
121
  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) {
122
+ var _ref3 = _temp2 === void 0 ? {} : _temp2,
123
+ _ref3$method = _ref3.method,
124
+ method = _ref3$method === void 0 ? 'GET' : _ref3$method,
125
+ headers = _ref3.headers,
126
+ _ref3$body = _ref3.body,
127
+ body = _ref3$body === void 0 ? '' : _ref3$body,
128
+ placeholderKey = _ref3.placeholderKey,
129
+ _ref3$beforeSave = _ref3.beforeSave,
130
+ beforeSave = _ref3$beforeSave === void 0 ? function (prevPage, receivedPage) {
123
131
  return receivedPage;
124
- } : _ref4$beforeSave,
125
- _ref4$revisit = _ref4.revisit,
126
- revisit = _ref4$revisit === void 0 ? false : _ref4$revisit;
132
+ } : _ref3$beforeSave,
133
+ _ref3$revisit = _ref3.revisit,
134
+ revisit = _ref3$revisit === void 0 ? false : _ref3$revisit;
127
135
 
128
136
  path = (0, _utils.withoutBusters)(path);
129
137
  var pageKey = (0, _utils.urlToPageKey)(path);
130
138
  return function (dispatch, getState) {
131
- var currentKey = getState().superglue.currentPageKey;
132
- dispatch(clearFlash({
133
- pageKey: currentKey
134
- }));
135
139
  placeholderKey = placeholderKey && (0, _utils.urlToPageKey)(placeholderKey);
136
140
  var hasPlaceholder = !!getState().pages[placeholderKey];
137
141
 
@@ -160,14 +164,19 @@ function visit(path, _temp2) {
160
164
  method: method,
161
165
  signal: signal
162
166
  });
167
+ var currentPageKey = getState().superglue.currentPageKey;
168
+ dispatch(beforeVisit({
169
+ currentPageKey: currentPageKey,
170
+ fetchArgs: fetchArgs
171
+ }));
163
172
  dispatch(beforeFetch({
164
173
  fetchArgs: fetchArgs
165
174
  }));
166
175
  lastVisitController.abort();
167
176
  lastVisitController = controller;
168
- return fetch.apply(void 0, fetchArgs).then(_utils.parseResponse).then(function (_ref5) {
169
- var rsp = _ref5.rsp,
170
- json = _ref5.json;
177
+ return fetch.apply(void 0, fetchArgs).then(_utils.parseResponse).then(function (_ref4) {
178
+ var rsp = _ref4.rsp,
179
+ json = _ref4.json;
171
180
 
172
181
  var _getState2 = getState(),
173
182
  superglue = _getState2.superglue,
package/actions.js CHANGED
@@ -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';
package/index.js CHANGED
@@ -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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thoughtbot/superglue",
3
- "version": "0.50.0-beta1",
3
+ "version": "0.50.0",
4
4
  "description": "Use a vanilla Rails with React and Redux",
5
5
  "repository": {
6
6
  "type": "git",
package/reducers/index.js CHANGED
@@ -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:
package/utils/react.js CHANGED
@@ -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
  }