@thoughtbot/superglue 0.0.0 → 0.30.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 +122 -0
- package/action_creators/index.js +160 -0
- package/action_creators/requests.js +207 -0
- package/actions.js +28 -0
- package/components/Nav.js +186 -0
- package/components/RailsTag.js +71 -0
- package/config.js +9 -0
- package/index.js +263 -0
- package/middleware.js +80 -0
- package/package.json +48 -6
- package/reducers/index.js +288 -0
- package/utils/helpers.js +36 -0
- package/utils/immutability.js +176 -0
- package/utils/index.js +59 -0
- package/utils/react.js +52 -0
- package/utils/request.js +132 -0
- package/utils/ujs.js +138 -0
- package/utils/url.js +126 -0
- package/utils/window.js +15 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports["default"] = void 0;
|
|
5
|
+
|
|
6
|
+
var _react = _interopRequireDefault(require("react"));
|
|
7
|
+
|
|
8
|
+
var _htmlReactParser = _interopRequireWildcard(require("html-react-parser"));
|
|
9
|
+
|
|
10
|
+
var _attributesToProps = _interopRequireDefault(require("html-react-parser/lib/attributes-to-props"));
|
|
11
|
+
|
|
12
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
+
|
|
14
|
+
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); }
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
|
+
|
|
20
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
21
|
+
|
|
22
|
+
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
|
23
|
+
|
|
24
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
25
|
+
|
|
26
|
+
var RailsTag = /*#__PURE__*/function (_React$Component) {
|
|
27
|
+
_inheritsLoose(RailsTag, _React$Component);
|
|
28
|
+
|
|
29
|
+
function RailsTag(props) {
|
|
30
|
+
var _this;
|
|
31
|
+
|
|
32
|
+
_this = _React$Component.call(this, props) || this;
|
|
33
|
+
_this.replace = _this.replace.bind(_assertThisInitialized(_this));
|
|
34
|
+
return _this;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var _proto = RailsTag.prototype;
|
|
38
|
+
|
|
39
|
+
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
|
|
40
|
+
return this.props.html !== nextProps.html;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
_proto.replace = function replace(domNode) {
|
|
44
|
+
var parent = domNode.parent,
|
|
45
|
+
type = domNode.type,
|
|
46
|
+
name = domNode.name,
|
|
47
|
+
attribs = domNode.attribs,
|
|
48
|
+
children = domNode.children;
|
|
49
|
+
|
|
50
|
+
if (!parent && type === 'tag') {
|
|
51
|
+
var nextProps = Object.assign({}, this.props, (0, _attributesToProps["default"])(attribs), {
|
|
52
|
+
children: (0, _htmlReactParser.domToReact)(children)
|
|
53
|
+
});
|
|
54
|
+
delete nextProps.html;
|
|
55
|
+
return /*#__PURE__*/_react["default"].createElement(name, nextProps);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
_proto.render = function render() {
|
|
60
|
+
return (0, _htmlReactParser["default"])(this.props.html, {
|
|
61
|
+
replace: this.replace
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return RailsTag;
|
|
66
|
+
}(_react["default"].Component);
|
|
67
|
+
|
|
68
|
+
exports["default"] = RailsTag;
|
|
69
|
+
RailsTag.propTypes = {
|
|
70
|
+
html: _propTypes["default"].string
|
|
71
|
+
};
|
package/config.js
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.updateFragments = exports.superglueReducer = exports.pageReducer = exports.mapDispatchToPropsIncludingVisitAndRemote = exports.getIn = exports.fragmentMiddleware = 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
|
+
var _redux = require("redux");
|
|
28
|
+
|
|
29
|
+
var _reduxThunk = _interopRequireDefault(require("redux-thunk"));
|
|
30
|
+
|
|
31
|
+
var _reactRedux = require("react-redux");
|
|
32
|
+
|
|
33
|
+
var _history = require("history");
|
|
34
|
+
|
|
35
|
+
var _Nav = _interopRequireDefault(require("./components/Nav"));
|
|
36
|
+
|
|
37
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
38
|
+
|
|
39
|
+
var _react2 = require("./utils/react");
|
|
40
|
+
|
|
41
|
+
exports.mapStateToProps = _react2.mapStateToProps;
|
|
42
|
+
exports.mapDispatchToProps = _react2.mapDispatchToProps;
|
|
43
|
+
exports.mapDispatchToPropsIncludingVisitAndRemote = _react2.mapDispatchToPropsIncludingVisitAndRemote;
|
|
44
|
+
|
|
45
|
+
var _middleware = require("./middleware");
|
|
46
|
+
|
|
47
|
+
exports.fragmentMiddleware = _middleware.fragmentMiddleware;
|
|
48
|
+
|
|
49
|
+
var _immutability = require("./utils/immutability");
|
|
50
|
+
|
|
51
|
+
exports.getIn = _immutability.getIn;
|
|
52
|
+
|
|
53
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
54
|
+
|
|
55
|
+
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
|
56
|
+
|
|
57
|
+
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); }
|
|
58
|
+
|
|
59
|
+
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); }
|
|
60
|
+
|
|
61
|
+
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; } }
|
|
62
|
+
|
|
63
|
+
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
64
|
+
|
|
65
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
66
|
+
|
|
67
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
68
|
+
|
|
69
|
+
function pageToInitialState(key, page) {
|
|
70
|
+
var _pages;
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
pages: (_pages = {}, _pages[key] = page, _pages)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function start(_ref) {
|
|
78
|
+
var initialPage = _ref.initialPage,
|
|
79
|
+
_ref$baseUrl = _ref.baseUrl,
|
|
80
|
+
baseUrl = _ref$baseUrl === void 0 ? _config.config.baseUrl : _ref$baseUrl,
|
|
81
|
+
_ref$maxPages = _ref.maxPages,
|
|
82
|
+
maxPages = _ref$maxPages === void 0 ? _config.config.maxPages : _ref$maxPages,
|
|
83
|
+
path = _ref.path;
|
|
84
|
+
var initialPageKey = (0, _utils.urlToPageKey)((0, _urlParse["default"])(path).href);
|
|
85
|
+
var csrfToken = initialPage.csrfToken;
|
|
86
|
+
var location = (0, _urlParse["default"])(path);
|
|
87
|
+
_config.config.baseUrl = baseUrl;
|
|
88
|
+
_config.config.maxPages = maxPages;
|
|
89
|
+
return {
|
|
90
|
+
reducer: _reducers.rootReducer,
|
|
91
|
+
prepareStore: function prepareStore(store) {
|
|
92
|
+
store.dispatch({
|
|
93
|
+
type: _actions.HISTORY_CHANGE,
|
|
94
|
+
payload: {
|
|
95
|
+
pathname: location.pathname,
|
|
96
|
+
search: location.query,
|
|
97
|
+
hash: location.hash
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
store.dispatch((0, _action_creators.saveAndProcessPage)(initialPageKey, initialPage));
|
|
101
|
+
store.dispatch({
|
|
102
|
+
type: _actions.SET_CSRF_TOKEN,
|
|
103
|
+
payload: {
|
|
104
|
+
csrfToken: csrfToken
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
initialState: pageToInitialState(initialPageKey, initialPage),
|
|
109
|
+
initialPageKey: initialPageKey
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
var NotImplementedError = /*#__PURE__*/function (_Error) {
|
|
114
|
+
_inheritsLoose(NotImplementedError, _Error);
|
|
115
|
+
|
|
116
|
+
function NotImplementedError(message) {
|
|
117
|
+
var _this;
|
|
118
|
+
|
|
119
|
+
_this = _Error.call(this, message) || this;
|
|
120
|
+
_this.name = _this.constructor.name;
|
|
121
|
+
return _this;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return NotImplementedError;
|
|
125
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
126
|
+
|
|
127
|
+
var ApplicationBase = /*#__PURE__*/function (_React$Component) {
|
|
128
|
+
_inheritsLoose(ApplicationBase, _React$Component);
|
|
129
|
+
|
|
130
|
+
function ApplicationBase(props) {
|
|
131
|
+
var _this2$history;
|
|
132
|
+
|
|
133
|
+
var _this2;
|
|
134
|
+
|
|
135
|
+
_this2 = _React$Component.call(this, props) || this;
|
|
136
|
+
_this2.hasWindow = typeof window !== 'undefined'; // Create a navigator Ref for UJS attributes and to enhance the base `visit`
|
|
137
|
+
// and `visit` thunks
|
|
138
|
+
|
|
139
|
+
_this2.navigatorRef = /*#__PURE__*/_react["default"].createRef(); // Retrieve initial values and methods to prepare the store.
|
|
140
|
+
|
|
141
|
+
var _start = start({
|
|
142
|
+
initialPage: _this2.props.initialPage,
|
|
143
|
+
baseUrl: _this2.props.baseUrl,
|
|
144
|
+
path: _this2.props.path // The max number of pages to keep in the store. Default is 20
|
|
145
|
+
// maxPages: 20
|
|
146
|
+
|
|
147
|
+
}),
|
|
148
|
+
prepareStore = _start.prepareStore,
|
|
149
|
+
initialState = _start.initialState,
|
|
150
|
+
initialPageKey = _start.initialPageKey,
|
|
151
|
+
reducer = _start.reducer;
|
|
152
|
+
|
|
153
|
+
_this2.initialPageKey = initialPageKey; // Build the store and pass Superglue's provided reducer to be combined with
|
|
154
|
+
// your reducers located at `application_reducer.js`
|
|
155
|
+
|
|
156
|
+
_this2.store = _this2.buildStore(initialState, reducer); // Fire initial events and populate the store
|
|
157
|
+
|
|
158
|
+
prepareStore(_this2.store); // Build history
|
|
159
|
+
|
|
160
|
+
_this2.history = _this2.createHistory();
|
|
161
|
+
|
|
162
|
+
(_this2$history = _this2.history).replace.apply(_this2$history, (0, _utils.argsForHistory)(_this2.props.path));
|
|
163
|
+
|
|
164
|
+
var nextMapping = Object.assign({}, _this2.mapping());
|
|
165
|
+
|
|
166
|
+
for (var key in nextMapping) {
|
|
167
|
+
var component = nextMapping[key];
|
|
168
|
+
nextMapping[key] = (0, _reactRedux.connect)(_react2.mapStateToProps, _react2.mapDispatchToProps)(component);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
_this2.connectedMapping = nextMapping; // Build visit and remote thunks
|
|
172
|
+
// Your modified `visit` and `remote` will get passed below to the
|
|
173
|
+
// Nav component then to your components
|
|
174
|
+
//
|
|
175
|
+
// You can access them via `this.props.visit` or `this.props.remote`. In
|
|
176
|
+
// your page components
|
|
177
|
+
|
|
178
|
+
var _this2$visitAndRemote = _this2.visitAndRemote(_this2.navigatorRef, _this2.store),
|
|
179
|
+
visit = _this2$visitAndRemote.visit,
|
|
180
|
+
remote = _this2$visitAndRemote.remote;
|
|
181
|
+
|
|
182
|
+
_this2.visit = visit;
|
|
183
|
+
_this2.remote = remote;
|
|
184
|
+
return _this2;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
var _proto = ApplicationBase.prototype;
|
|
188
|
+
|
|
189
|
+
_proto.visitAndRemote = function visitAndRemote() {
|
|
190
|
+
throw new NotImplementedError('Implement this');
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
_proto.componentDidMount = function componentDidMount() {
|
|
194
|
+
var appEl = this.props.appEl; // Create the ujs event handlers. You can change the ujsAttributePrefix
|
|
195
|
+
// in the event the data attribute conflicts with another.
|
|
196
|
+
|
|
197
|
+
this.ujsHandlers = (0, _utils.ujsHandlers)({
|
|
198
|
+
visit: this.visit,
|
|
199
|
+
remote: this.remote,
|
|
200
|
+
store: this.store,
|
|
201
|
+
ujsAttributePrefix: 'data-bz'
|
|
202
|
+
});
|
|
203
|
+
var _this$ujsHandlers = this.ujsHandlers,
|
|
204
|
+
onClick = _this$ujsHandlers.onClick,
|
|
205
|
+
onSubmit = _this$ujsHandlers.onSubmit;
|
|
206
|
+
appEl.addEventListener('click', onClick);
|
|
207
|
+
appEl.addEventListener('submit', onSubmit);
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
211
|
+
var appEl = this.props.appEl;
|
|
212
|
+
var _this$ujsHandlers2 = this.ujsHandlers,
|
|
213
|
+
onClick = _this$ujsHandlers2.onClick,
|
|
214
|
+
onSubmit = _this$ujsHandlers2.onSubmit;
|
|
215
|
+
appEl.removeEventListener('click', onClick);
|
|
216
|
+
appEl.removeEventListener('submit', onSubmit);
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
_proto.buildStore = function buildStore(initialState, reducer) {
|
|
220
|
+
var store = (0, _redux.createStore)((0, _redux.combineReducers)(reducer), initialState, (0, _redux.compose)((0, _redux.applyMiddleware)(_reduxThunk["default"])));
|
|
221
|
+
return store;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
_proto.createHistory = function createHistory() {
|
|
225
|
+
if (this.hasWindow) {
|
|
226
|
+
// This is used for client side rendering
|
|
227
|
+
return (0, _history.createBrowserHistory)({});
|
|
228
|
+
} else {
|
|
229
|
+
// This is used for server side rendering
|
|
230
|
+
return (0, _history.createMemoryHistory)({});
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
_proto.mapping = function mapping() {
|
|
235
|
+
throw new NotImplementedError('Implement this');
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
_proto.render = function render() {
|
|
239
|
+
// The Nav component is pretty bare and can be inherited from for custom
|
|
240
|
+
// behavior or replaced with your own.
|
|
241
|
+
return /*#__PURE__*/_react["default"].createElement(_reactRedux.Provider, {
|
|
242
|
+
store: this.store
|
|
243
|
+
}, /*#__PURE__*/_react["default"].createElement(_Nav["default"], {
|
|
244
|
+
store: this.store,
|
|
245
|
+
ref: this.navigatorRef,
|
|
246
|
+
visit: this.visit,
|
|
247
|
+
remote: this.remote,
|
|
248
|
+
mapping: this.connectedMapping,
|
|
249
|
+
history: this.history,
|
|
250
|
+
initialPageKey: this.initialPageKey
|
|
251
|
+
}));
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
return ApplicationBase;
|
|
255
|
+
}(_react["default"].Component);
|
|
256
|
+
|
|
257
|
+
exports.ApplicationBase = ApplicationBase;
|
|
258
|
+
ApplicationBase.propTypes = {
|
|
259
|
+
initialPage: _propTypes["default"].object,
|
|
260
|
+
baseUrl: _propTypes["default"].string,
|
|
261
|
+
path: _propTypes["default"].string,
|
|
262
|
+
appEl: _propTypes["default"].object
|
|
263
|
+
};
|
package/middleware.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
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 = 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
|
+
};
|
|
79
|
+
|
|
80
|
+
exports.fragmentMiddleware = fragmentMiddleware;
|
package/package.json
CHANGED
|
@@ -1,12 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thoughtbot/superglue",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
3
|
+
"version": "0.30.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
|
+
},
|
|
6
9
|
"author": "Johny Ho",
|
|
7
10
|
"license": "MIT",
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
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": "^4.7.1",
|
|
30
|
+
"html-react-parser": "^1.2.6",
|
|
31
|
+
"jest": "^27.0.4",
|
|
32
|
+
"node-fetch": "^2.6.1",
|
|
33
|
+
"prettier": "^2.3.1",
|
|
34
|
+
"prop-types": "^15.7.2",
|
|
35
|
+
"react": "^16.4.0",
|
|
36
|
+
"react-dom": "^16.4.0",
|
|
37
|
+
"react-redux": "^7.2.4",
|
|
38
|
+
"redux": "^4.1.0",
|
|
39
|
+
"redux-mock-store": "^1.5.4",
|
|
40
|
+
"redux-thunk": "^2.3.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"html-react-parser": ">=1.2.6",
|
|
44
|
+
"react": ">=16",
|
|
45
|
+
"redux": ">=4.1",
|
|
46
|
+
"history": "^4.7.1",
|
|
47
|
+
"react-redux": ">=7.2",
|
|
48
|
+
"redux-thunk": ">=2.3"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"abortcontroller-polyfill": "^1.7.3",
|
|
52
|
+
"url-parse": "^1.5.1"
|
|
11
53
|
}
|
|
12
54
|
}
|