@@ -8,17 +8,18 @@ import type {
8
8
} from './types/index' ;
9
9
10
10
import createReactOutput from './createReactOutput' ;
11
- import { isServerRenderHash } from './isServerRenderResult' ;
11
+ import { isServerRenderHash } from './isServerRenderResult' ;
12
12
import reactHydrateOrRender from './reactHydrateOrRender' ;
13
13
14
14
declare global {
15
15
interface Window {
16
- ReactOnRails : ReactOnRailsType ;
17
- __REACT_ON_RAILS_EVENT_HANDLERS_RAN_ONCE__ ?: boolean ;
16
+ ReactOnRails : ReactOnRailsType ;
17
+ __REACT_ON_RAILS_EVENT_HANDLERS_RAN_ONCE__ ?: boolean ;
18
18
}
19
+
19
20
namespace NodeJS {
20
21
interface Global {
21
- ReactOnRails : ReactOnRailsType ;
22
+ ReactOnRails : ReactOnRailsType ;
22
23
}
23
24
}
24
25
namespace Turbolinks {
@@ -67,7 +68,7 @@ function turboInstalled() {
67
68
return false ;
68
69
}
69
70
70
- function reactOnRailsHtmlElements ( ) : HTMLCollectionOf < Element > {
71
+ function reactOnRailsHtmlElements ( ) : HTMLCollectionOf < Element > {
71
72
return document . getElementsByClassName ( 'js-react-on-rails-component' ) ;
72
73
}
73
74
@@ -80,7 +81,7 @@ function forEachReactOnRailsComponentInitialize(fn: (element: Element, railsCont
80
81
81
82
function initializeStore ( el : Element , railsContext : RailsContext ) : void {
82
83
const context = findContext ( ) ;
83
- const name = el . getAttribute ( REACT_ON_RAILS_STORE_ATTRIBUTE ) || "" ;
84
+ const name = el . getAttribute ( REACT_ON_RAILS_STORE_ATTRIBUTE ) || '' ;
84
85
const props = ( el . textContent !== null ) ? JSON . parse ( el . textContent ) : { } ;
85
86
const storeGenerator = context . ReactOnRails . getStoreGenerator ( name ) ;
86
87
const store = storeGenerator ( props , railsContext ) ;
@@ -107,15 +108,15 @@ function delegateToRenderer(
107
108
props : Record < string , string > ,
108
109
railsContext : RailsContext ,
109
110
domNodeId : string ,
110
- trace : boolean
111
+ trace : boolean ,
111
112
) : boolean {
112
113
const { name, component, isRenderer } = componentObj ;
113
114
114
115
if ( isRenderer ) {
115
116
if ( trace ) {
116
117
console . log ( `\
117
118
DELEGATING TO RENDERER ${ name } for dom node with id: ${ domNodeId } with props, railsContext:` ,
118
- props , railsContext ) ;
119
+ props , railsContext ) ;
119
120
}
120
121
121
122
( component as RenderFunction ) ( props , railsContext , domNodeId ) ;
@@ -126,7 +127,7 @@ DELEGATING TO RENDERER ${name} for dom node with id: ${domNodeId} with props, ra
126
127
}
127
128
128
129
function domNodeIdForEl ( el : Element ) : string {
129
- return el . getAttribute ( 'data-dom-id' ) || "" ;
130
+ return el . getAttribute ( 'data-dom-id' ) || '' ;
130
131
}
131
132
132
133
/**
@@ -137,10 +138,10 @@ function domNodeIdForEl(el: Element): string {
137
138
function render ( el : Element , railsContext : RailsContext ) : void {
138
139
const context = findContext ( ) ;
139
140
// This must match lib/react_on_rails/helper.rb
140
- const name = el . getAttribute ( 'data-component-name' ) || "" ;
141
+ const name = el . getAttribute ( 'data-component-name' ) || '' ;
141
142
const domNodeId = domNodeIdForEl ( el ) ;
142
143
const props = ( el . textContent !== null ) ? JSON . parse ( el . textContent ) : { } ;
143
- const trace = el . getAttribute ( 'data-trace' ) === " true" ;
144
+ const trace = el . getAttribute ( 'data-trace' ) === ' true' ;
144
145
145
146
try {
146
147
const domNode = document . getElementById ( domNodeId ) ;
@@ -187,7 +188,7 @@ function parseRailsContext(): RailsContext | null {
187
188
}
188
189
189
190
if ( ! el . textContent ) {
190
- throw new Error ( " The HTML element with ID 'js-react-on-rails-context' has no textContent" ) ;
191
+ throw new Error ( ' The HTML element with ID \ 'js-react-on-rails-context\ ' has no textContent' ) ;
191
192
}
192
193
193
194
return JSON . parse ( el . textContent ) ;
@@ -208,7 +209,9 @@ export function reactOnRailsPageLoaded(): void {
208
209
function unmount ( el : Element ) : void {
209
210
const domNodeId = domNodeIdForEl ( el ) ;
210
211
const domNode = document . getElementById ( domNodeId ) ;
211
- if ( domNode === null ) { return ; }
212
+ if ( domNode === null ) {
213
+ return ;
214
+ }
212
215
try {
213
216
ReactDOM . unmountComponentAtNode ( domNode ) ;
214
217
} catch ( e : any ) {
@@ -258,7 +261,7 @@ function renderInit(): void {
258
261
}
259
262
}
260
263
261
- function isWindow ( context : Window | NodeJS . Global ) : context is Window {
264
+ function isWindow ( context : Window | NodeJS . Global ) : context is Window {
262
265
return ( context as Window ) . document !== undefined ;
263
266
}
264
267
0 commit comments