@@ -78,6 +78,34 @@ return /******/ (function(modules) { // webpackBootstrap
78
78
/************************************************************************/
79
79
/******/ ( [
80
80
/* 0 */
81
+ /***/ ( function ( module , exports ) {
82
+
83
+ // Assume className is simple and can be found at top-level (window).
84
+ // Fallback to eval to handle cases like 'My.React.ComponentName'.
85
+ // Also, try to gracefully import Babel 6 style default exports
86
+ var topLevel = typeof window === "undefined" ? this : window ;
87
+
88
+ module . exports = function ( className ) {
89
+ var constructor ;
90
+ // Try to access the class globally first
91
+ constructor = topLevel [ className ] ;
92
+
93
+ // If that didn't work, try eval
94
+ if ( ! constructor ) {
95
+ constructor = eval ( className ) ;
96
+ }
97
+
98
+ // Lastly, if there is a default attribute try that
99
+ if ( constructor && constructor [ 'default' ] ) {
100
+ constructor = constructor [ 'default' ] ;
101
+ }
102
+
103
+ return constructor ;
104
+ }
105
+
106
+
107
+ /***/ } ) ,
108
+ /* 1 */
81
109
/***/ ( function ( module , exports , __webpack_require__ ) {
82
110
83
111
var nativeEvents = __webpack_require__ ( 7 )
@@ -118,58 +146,26 @@ module.exports = function(ujs) {
118
146
}
119
147
120
148
121
- /***/ } ) ,
122
- /* 1 */
123
- /***/ ( function ( module , exports ) {
124
-
125
- // Assume className is simple and can be found at top-level (window).
126
- // Fallback to eval to handle cases like 'My.React.ComponentName'.
127
- // Also, try to gracefully import Babel 6 style default exports
128
- var topLevel = typeof window === "undefined" ? this : window ;
129
-
130
- module . exports = function ( className ) {
131
- var constructor ;
132
- // Try to access the class globally first
133
- constructor = topLevel [ className ] ;
134
-
135
- // If that didn't work, try eval
136
- if ( ! constructor ) {
137
- constructor = eval ( className ) ;
138
- }
139
-
140
- // Lastly, if there is a default attribute try that
141
- if ( constructor && constructor [ 'default' ] ) {
142
- constructor = constructor [ 'default' ] ;
143
- }
144
-
145
- return constructor ;
146
- }
147
-
148
-
149
149
/***/ } ) ,
150
150
/* 2 */
151
- /***/ ( function ( module , exports ) {
151
+ /***/ ( function ( module , exports , __webpack_require__ ) {
152
+
153
+ // Make a function which:
154
+ // - First tries to require the name
155
+ // - Then falls back to global lookup
156
+ var fromGlobal = __webpack_require__ ( 0 )
157
+ var fromRequireContext = __webpack_require__ ( 12 )
152
158
153
- // Load React components by requiring them from "components/", for example:
154
- //
155
- // - "pages/index" -> `require("components/pages/index")`
156
- // - "pages/show.Header" -> `require("components/pages/show").Header`
157
- // - "pages/show.Body.Content" -> `require("components/pages/show").Body.Content`
158
- //
159
159
module . exports = function ( reqctx ) {
160
+ var fromCtx = fromRequireContext ( reqctx )
160
161
return function ( className ) {
161
- var parts = className . split ( "." )
162
- var filename = parts . shift ( )
163
- var keys = parts
164
- // Load the module:
165
- var component = reqctx ( "./" + filename )
166
- // Then access each key:
167
- keys . forEach ( function ( k ) {
168
- component = component [ k ]
169
- } )
170
- // support `export default`
171
- if ( component . __esModule ) {
172
- component = component [ "default" ]
162
+ var component ;
163
+ try {
164
+ // `require` will raise an error if this className isn't found:
165
+ component = fromCtx ( className )
166
+ } catch ( err ) {
167
+ // fallback to global:
168
+ component = fromGlobal ( className )
173
169
}
174
170
return component
175
171
}
@@ -202,9 +198,9 @@ var React = __webpack_require__(3)
202
198
var ReactDOM = __webpack_require__ ( 4 )
203
199
var ReactDOMServer = __webpack_require__ ( 5 )
204
200
205
- var detectEvents = __webpack_require__ ( 0 )
206
- var constructorFromGlobal = __webpack_require__ ( 1 )
207
- var constructorFromRequireContext = __webpack_require__ ( 2 )
201
+ var detectEvents = __webpack_require__ ( 1 )
202
+ var constructorFromGlobal = __webpack_require__ ( 0 )
203
+ var constructorFromRequireContextWithGlobalFallback = __webpack_require__ ( 2 )
208
204
209
205
var ReactRailsUJS = {
210
206
// This attribute holds the name of component which should be mounted
@@ -255,8 +251,8 @@ var ReactRailsUJS = {
255
251
// the default is ReactRailsUJS.ComponentGlobal
256
252
getConstructor : constructorFromGlobal ,
257
253
258
- loadContext : function ( req ) {
259
- this . getConstructor = constructorFromRequireContext ( req )
254
+ useContext : function ( req ) {
255
+ this . getConstructor = constructorFromRequireContextWithGlobalFallback ( req )
260
256
} ,
261
257
262
258
// Render `componentName` with `props` to a string,
@@ -360,8 +356,9 @@ module.exports = {
360
356
module . exports = {
361
357
// Turbolinks 5+ got rid of named events (?!)
362
358
setup : function ( ujs ) {
363
- ujs . handleEvent ( 'turbolinks:load' , function ( ) { ujs . mountComponents ( ) } ) ;
364
- ujs . handleEvent ( 'turbolinks:before-render' , function ( ) { ujs . unmountComponents ( ) } ) ;
359
+ ujs . handleEvent ( 'DOMContentLoaded' , function ( ) { ujs . mountComponents ( ) } )
360
+ ujs . handleEvent ( 'turbolinks:render' , function ( ) { ujs . mountComponents ( ) } )
361
+ ujs . handleEvent ( 'turbolinks:before-render' , function ( ) { ujs . unmountComponents ( ) } )
365
362
} ,
366
363
}
367
364
@@ -397,6 +394,36 @@ module.exports = {
397
394
}
398
395
399
396
397
+ /***/ } ) ,
398
+ /* 12 */
399
+ /***/ ( function ( module , exports ) {
400
+
401
+ // Load React components by requiring them from "components/", for example:
402
+ //
403
+ // - "pages/index" -> `require("components/pages/index")`
404
+ // - "pages/show.Header" -> `require("components/pages/show").Header`
405
+ // - "pages/show.Body.Content" -> `require("components/pages/show").Body.Content`
406
+ //
407
+ module . exports = function ( reqctx ) {
408
+ return function ( className ) {
409
+ var parts = className . split ( "." )
410
+ var filename = parts . shift ( )
411
+ var keys = parts
412
+ // Load the module:
413
+ var component = reqctx ( "./" + filename )
414
+ // Then access each key:
415
+ keys . forEach ( function ( k ) {
416
+ component = component [ k ]
417
+ } )
418
+ // support `export default`
419
+ if ( component . __esModule ) {
420
+ component = component [ "default" ]
421
+ }
422
+ return component
423
+ }
424
+ }
425
+
426
+
400
427
/***/ } )
401
428
/******/ ] ) ;
402
429
} ) ;
0 commit comments