File tree Expand file tree Collapse file tree 1 file changed +14
-12
lines changed Expand file tree Collapse file tree 1 file changed +14
-12
lines changed Original file line number Diff line number Diff line change 36
36
}
37
37
} ;
38
38
39
- // Register page load & unload events
40
- if ( $ ) {
41
- $ ( mountReactComponents ) ;
42
- $ ( window ) . unload ( unmountReactComponents ) ;
43
- } else {
44
- document . addEventListener ( 'DOMContentLoaded' , mountReactComponents ) ;
45
- window . addEventListener ( 'unload' , unmountReactComponents ) ;
46
- }
47
-
48
- // Turbolinks specified events
49
- if ( typeof Turbolinks !== 'undefined' ) {
39
+ var handleTurbolinksEvents = function ( ) {
50
40
var handleEvent ;
51
41
if ( $ ) {
52
42
handleEvent = function ( eventName , callback ) {
59
49
}
60
50
handleEvent ( 'page:change' , mountReactComponents ) ;
61
51
handleEvent ( 'page:before-change' , unmountReactComponents ) ;
62
- }
52
+ } ;
53
+
54
+ var handleNativeEvents = function ( ) {
55
+ if ( $ ) {
56
+ $ ( mountReactComponents ) ;
57
+ $ ( window ) . unload ( unmountReactComponents ) ;
58
+ } else {
59
+ document . addEventListener ( 'DOMContentLoaded' , mountReactComponents ) ;
60
+ window . addEventListener ( 'unload' , unmountReactComponents ) ;
61
+ }
62
+ } ;
63
+
64
+ typeof Turbolinks !== 'undefined' ? handleTurbolinksEvents ( ) : handleNativeEvents ( ) ;
63
65
} ) ( document , window , React ) ;
You can’t perform that action at this time.
0 commit comments