react-rails 2.0.0 → 2.0.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +9 -2
- data/lib/assets/javascripts/react_ujs.js +94 -18
- data/lib/react/rails/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d281b77d99197720b6074abc35e3ebb9be613c2
|
4
|
+
data.tar.gz: cc3103861584d6b55f450b39e03d8df5def19e1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e393b22c5f5c93be85e919d334d21c9421484d5e82fd59cd06029d65a2f549ebfe32b7a9b7b2fb6c8b66559e5f953c876db31021e34d7a5d851a6527796638a
|
7
|
+
data.tar.gz: fbb538016c5a28fd5d455fd9fd615009942079d89d2b7a31d753102c13a7d36afc1d88bd981fc8b7169ddc9bd77cadd59de6be781dd89b7d68e4825a378e7ee4
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,15 @@
|
|
8
8
|
|
9
9
|
#### Bug Fixes
|
10
10
|
|
11
|
+
## 2.0.2 (April 13, 2017)
|
12
|
+
|
13
|
+
#### New Features
|
14
|
+
|
15
|
+
- Rerun events detection at any time with `ReactRailsUJS.detectEvents()` #693
|
16
|
+
- Make the NPM version of `react_ujs` match the Rubygem version
|
17
|
+
|
18
|
+
`2.0.1` was skipped because a bad version of `react_ujs` was published to NPM.
|
19
|
+
|
11
20
|
## 2.0.0 (April 13, 2017)
|
12
21
|
|
13
22
|
#### Breaking Changes
|
data/README.md
CHANGED
@@ -59,7 +59,7 @@ When you add a component to `components/`, you can [render it in a Rails view](#
|
|
59
59
|
The component name tells `react-rails` where to load the component. For example:
|
60
60
|
|
61
61
|
`react_component` call | component `require`
|
62
|
-
|
62
|
+
-----|-----
|
63
63
|
`react_component("Item")` | `require("Item")`
|
64
64
|
`react_component("items/index")` | `require("items/index")`
|
65
65
|
`react_component("items.Index")` | `require("items").Index`
|
@@ -245,7 +245,14 @@ You can use this when the DOM is modified by AJAX calls or modal windows.
|
|
245
245
|
|
246
246
|
`ReactRailsUJS` will automatically mount components on `<%= react_component(...) %>` tags and unmount them when appropriate.
|
247
247
|
|
248
|
-
|
248
|
+
If you need to re-detect events, you can call `detectEvents`:
|
249
|
+
|
250
|
+
```js
|
251
|
+
// Remove previous event handlers and add new ones:
|
252
|
+
ReactRailsUJS.detectEvents()
|
253
|
+
```
|
254
|
+
|
255
|
+
For example, if `Turbolinks` is loaded _after_ `ReactRailsUJS`, you'll need to call this again. This function removes previous handlers before adding new ones, so it's safe to call as often as needed.
|
249
256
|
|
250
257
|
### `getConstructor`
|
251
258
|
|
@@ -117,14 +117,36 @@ var turbolinksClassicEvents = __webpack_require__(10)
|
|
117
117
|
// see what things are globally available
|
118
118
|
// and setup event handlers to those things
|
119
119
|
module.exports = function(ujs) {
|
120
|
+
if (ujs.handleEvent) {
|
121
|
+
// We're calling this a second time -- remove previous handlers
|
122
|
+
turbolinksClassicEvents.teardown(ujs)
|
123
|
+
turbolinksEvents.teardown(ujs);
|
124
|
+
turbolinksClassicDeprecatedEvents.teardown(ujs);
|
125
|
+
pjaxEvents.teardown(ujs);
|
126
|
+
nativeEvents.teardown(ujs);
|
127
|
+
}
|
128
|
+
|
120
129
|
if (ujs.jQuery) {
|
121
130
|
ujs.handleEvent = function(eventName, callback) {
|
122
131
|
ujs.jQuery(document).on(eventName, callback);
|
123
132
|
};
|
124
|
-
|
133
|
+
ujs.removeEvent = function(eventName, callback) {
|
134
|
+
ujs.jQuery(document).off(eventName, callback);
|
135
|
+
}
|
136
|
+
} else if ('addEventListener' in window) {
|
125
137
|
ujs.handleEvent = function(eventName, callback) {
|
126
138
|
document.addEventListener(eventName, callback);
|
127
139
|
};
|
140
|
+
ujs.removeEvent = function(eventName, callback) {
|
141
|
+
document.removeEventListener(eventName, callback);
|
142
|
+
};
|
143
|
+
} else {
|
144
|
+
ujs.handleEvent = function(eventName, callback) {
|
145
|
+
window.attachEvent(eventName, callback);
|
146
|
+
};
|
147
|
+
ujs.removeEvent = function(eventName, callback) {
|
148
|
+
window.detachEvent(eventName, callback);
|
149
|
+
};
|
128
150
|
}
|
129
151
|
|
130
152
|
// Detect which kind of events to set up:
|
@@ -251,8 +273,11 @@ var ReactRailsUJS = {
|
|
251
273
|
// the default is ReactRailsUJS.ComponentGlobal
|
252
274
|
getConstructor: constructorFromGlobal,
|
253
275
|
|
254
|
-
|
255
|
-
|
276
|
+
// Given a Webpack `require.context`,
|
277
|
+
// try finding components with `require`,
|
278
|
+
// then falling back to global lookup.
|
279
|
+
useContext: function(requireContext) {
|
280
|
+
this.getConstructor = constructorFromRequireContextWithGlobalFallback(requireContext)
|
256
281
|
},
|
257
282
|
|
258
283
|
// Render `componentName` with `props` to a string,
|
@@ -298,11 +323,36 @@ var ReactRailsUJS = {
|
|
298
323
|
ReactDOM.unmountComponentAtNode(node);
|
299
324
|
}
|
300
325
|
},
|
326
|
+
|
327
|
+
// Check the global context for installed libraries
|
328
|
+
// and figure out which library to hook up to (pjax, Turbolinks, jQuery)
|
329
|
+
// This is called on load, but you can call it again if needed
|
330
|
+
// (It will unmount itself)
|
331
|
+
detectEvents: function() {
|
332
|
+
detectEvents(this)
|
333
|
+
},
|
301
334
|
}
|
302
335
|
|
336
|
+
// These stable references are so that handlers can be added and removed:
|
337
|
+
ReactRailsUJS.handleMount = function(e) {
|
338
|
+
var target = undefined;
|
339
|
+
if (e && e.target) {
|
340
|
+
target = e.target;
|
341
|
+
}
|
342
|
+
ReactRailsUJS.mountComponents(target);
|
343
|
+
}
|
344
|
+
ReactRailsUJS.handleUnmount = function(e) {
|
345
|
+
var target = undefined;
|
346
|
+
if (e && e.target) {
|
347
|
+
target = e.target;
|
348
|
+
}
|
349
|
+
ReactRailsUJS.unmountComponents(target);
|
350
|
+
}
|
351
|
+
|
352
|
+
|
303
353
|
if (typeof window !== "undefined") {
|
304
354
|
// Only setup events for browser (not server-rendering)
|
305
|
-
detectEvents(
|
355
|
+
ReactRailsUJS.detectEvents()
|
306
356
|
}
|
307
357
|
|
308
358
|
// It's a bit of a no-no to populate the global namespace,
|
@@ -324,13 +374,19 @@ module.exports = {
|
|
324
374
|
setup: function(ujs) {
|
325
375
|
if (ujs.jQuery) {
|
326
376
|
// Use jQuery if it's present:
|
327
|
-
ujs.
|
377
|
+
ujs.handleEvent("ready", ujs.handleMount);
|
328
378
|
} else if ('addEventListener' in window) {
|
329
|
-
|
379
|
+
ujs.handleEvent('DOMContentLoaded', ujs.handleMount);
|
330
380
|
} else {
|
331
381
|
// add support to IE8 without jQuery
|
332
|
-
|
382
|
+
ujs.handleEvent('onload', ujs.handleMount);
|
333
383
|
}
|
384
|
+
},
|
385
|
+
|
386
|
+
teardown: function(ujs) {
|
387
|
+
ujs.removeEvent("ready", ujs.handleMount);
|
388
|
+
ujs.removeEvent('DOMContentLoaded', ujs.handleMount);
|
389
|
+
ujs.removeEvent('onload', ujs.handleMount);
|
334
390
|
}
|
335
391
|
}
|
336
392
|
|
@@ -342,10 +398,16 @@ module.exports = {
|
|
342
398
|
module.exports = {
|
343
399
|
// pjax support
|
344
400
|
setup: function(ujs) {
|
345
|
-
ujs.handleEvent('ready',
|
346
|
-
ujs.handleEvent('pjax:end',
|
347
|
-
ujs.handleEvent('pjax:beforeReplace',
|
348
|
-
}
|
401
|
+
ujs.handleEvent('ready', ujs.handleMount);
|
402
|
+
ujs.handleEvent('pjax:end', ujs.handleMount);
|
403
|
+
ujs.handleEvent('pjax:beforeReplace', ujs.handleUnmount);
|
404
|
+
},
|
405
|
+
|
406
|
+
teardown: function(ujs) {
|
407
|
+
ujs.removeEvent('ready', ujs.handleMount);
|
408
|
+
ujs.removeEvent('pjax:end', ujs.handleMount);
|
409
|
+
ujs.removeEvent('pjax:beforeReplace', ujs.handleUnmount);
|
410
|
+
},
|
349
411
|
}
|
350
412
|
|
351
413
|
|
@@ -356,9 +418,15 @@ module.exports = {
|
|
356
418
|
module.exports = {
|
357
419
|
// Turbolinks 5+ got rid of named events (?!)
|
358
420
|
setup: function(ujs) {
|
359
|
-
ujs.handleEvent('DOMContentLoaded',
|
360
|
-
ujs.handleEvent('turbolinks:render',
|
361
|
-
ujs.handleEvent('turbolinks:before-render',
|
421
|
+
ujs.handleEvent('DOMContentLoaded', ujs.handleMount)
|
422
|
+
ujs.handleEvent('turbolinks:render', ujs.handleMount)
|
423
|
+
ujs.handleEvent('turbolinks:before-render', ujs.handleUnmount)
|
424
|
+
},
|
425
|
+
|
426
|
+
teardown: function(ujs) {
|
427
|
+
ujs.removeEvent('DOMContentLoaded', ujs.handleMount)
|
428
|
+
ujs.removeEvent('turbolinks:render', ujs.handleMount)
|
429
|
+
ujs.removeEvent('turbolinks:before-render', ujs.handleUnmount)
|
362
430
|
},
|
363
431
|
}
|
364
432
|
|
@@ -371,8 +439,12 @@ module.exports = {
|
|
371
439
|
// Attach handlers to Turbolinks-Classic events
|
372
440
|
// for mounting and unmounting components
|
373
441
|
setup: function(ujs) {
|
374
|
-
ujs.handleEvent(Turbolinks.EVENTS.CHANGE,
|
375
|
-
ujs.handleEvent(Turbolinks.EVENTS.BEFORE_UNLOAD,
|
442
|
+
ujs.handleEvent(Turbolinks.EVENTS.CHANGE, ujs.handleMount);
|
443
|
+
ujs.handleEvent(Turbolinks.EVENTS.BEFORE_UNLOAD, ujs.handleUnmount);
|
444
|
+
},
|
445
|
+
teardown: function(ujs) {
|
446
|
+
ujs.removeEvent(Turbolinks.EVENTS.CHANGE, ujs.handleMount);
|
447
|
+
ujs.removeEvent(Turbolinks.EVENTS.BEFORE_UNLOAD, ujs.handleUnmount);
|
376
448
|
}
|
377
449
|
}
|
378
450
|
|
@@ -388,8 +460,12 @@ module.exports = {
|
|
388
460
|
// https://github.com/reactjs/react-rails/issues/87
|
389
461
|
setup: function(ujs) {
|
390
462
|
Turbolinks.pagesCached(0)
|
391
|
-
ujs.handleEvent('page:change',
|
392
|
-
ujs.handleEvent('page:receive',
|
463
|
+
ujs.handleEvent('page:change', ujs.handleMount);
|
464
|
+
ujs.handleEvent('page:receive', ujs.handleUnmount);
|
465
|
+
},
|
466
|
+
teardown: function(ujs) {
|
467
|
+
ujs.removeEvent('page:change', ujs.handleMount);
|
468
|
+
ujs.removeEvent('page:receive', ujs.handleUnmount);
|
393
469
|
}
|
394
470
|
}
|
395
471
|
|
data/lib/react/rails/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module React
|
2
2
|
module Rails
|
3
3
|
# If you change this, make sure to update VERSIONS.md
|
4
|
-
#
|
5
|
-
VERSION = "2.0.
|
4
|
+
# and republish the UJS by updating package.json and `bundle exec rake ujs:publish`
|
5
|
+
VERSION = "2.0.2"
|
6
6
|
end
|
7
7
|
end
|