@@ -65,7 +65,7 @@ function debugTurbolinks(...msg: string[]): void {
6565}
6666
6767function turbolinksInstalled ( ) : boolean {
68- return ( typeof Turbolinks !== 'undefined' ) ;
68+ return typeof Turbolinks !== 'undefined' ;
6969}
7070
7171function turboInstalled ( ) {
@@ -82,7 +82,7 @@ function reactOnRailsHtmlElements(): HTMLCollectionOf<Element> {
8282
8383function initializeStore ( el : Element , context : Context , railsContext : RailsContext ) : void {
8484 const name = el . getAttribute ( REACT_ON_RAILS_STORE_ATTRIBUTE ) || '' ;
85- const props = ( el . textContent !== null ) ? JSON . parse ( el . textContent ) : { } ;
85+ const props = el . textContent !== null ? JSON . parse ( el . textContent ) : { } ;
8686 const storeGenerator = context . ReactOnRails . getStoreGenerator ( name ) ;
8787 const store = storeGenerator ( props , railsContext ) ;
8888 context . ReactOnRails . setStore ( name , store ) ;
@@ -96,7 +96,7 @@ function forEachStore(context: Context, railsContext: RailsContext): void {
9696}
9797
9898function turbolinksVersion5 ( ) : boolean {
99- return ( typeof Turbolinks . controller !== 'undefined' ) ;
99+ return typeof Turbolinks . controller !== 'undefined' ;
100100}
101101
102102function turbolinksSupported ( ) : boolean {
@@ -114,9 +114,12 @@ function delegateToRenderer(
114114
115115 if ( isRenderer ) {
116116 if ( trace ) {
117- console . log ( `\
117+ console . log (
118+ `\
118119DELEGATING TO RENDERER ${ name } for dom node with id: ${ domNodeId } with props, railsContext:` ,
119- props , railsContext ) ;
120+ props ,
121+ railsContext ,
122+ ) ;
120123 }
121124
122125 ( component as RenderFunction ) ( props , railsContext , domNodeId ) ;
@@ -138,7 +141,7 @@ function render(el: Element, context: Context, railsContext: RailsContext): void
138141 // This must match lib/react_on_rails/helper.rb
139142 const name = el . getAttribute ( 'data-component-name' ) || '' ;
140143 const domNodeId = domNodeIdForEl ( el ) ;
141- const props = ( el . textContent !== null ) ? JSON . parse ( el . textContent ) : { } ;
144+ const props = el . textContent !== null ? JSON . parse ( el . textContent ) : { } ;
142145 const trace = el . getAttribute ( 'data-trace' ) === 'true' ;
143146
144147 try {
@@ -167,15 +170,19 @@ function render(el: Element, context: Context, railsContext: RailsContext): void
167170You returned a server side type of react-router error: ${ JSON . stringify ( reactElementOrRouterResult ) }
168171You should return a React.Component always for the client side entry point.` ) ;
169172 } else {
170- const rootOrElement = reactHydrateOrRender ( domNode , reactElementOrRouterResult as ReactElement , shouldHydrate ) ;
173+ const rootOrElement = reactHydrateOrRender (
174+ domNode ,
175+ reactElementOrRouterResult as ReactElement ,
176+ shouldHydrate ,
177+ ) ;
171178 if ( supportsRootApi ) {
172179 context . roots . push ( rootOrElement as Root ) ;
173180 }
174181 }
175182 }
176183 } catch ( e : any ) {
177184 console . error ( e . message ) ;
178- e . message = `ReactOnRails encountered an error while rendering component: ${ name } . See above error message.`
185+ e . message = `ReactOnRails encountered an error while rendering component: ${ name } . See above error message.` ;
179186 throw e ;
180187 }
181188}
@@ -196,7 +203,7 @@ function parseRailsContext(): RailsContext | null {
196203 }
197204
198205 if ( ! el . textContent ) {
199- throw new Error ( ' The HTML element with ID \ 'js-react-on-rails-context\ ' has no textContent' ) ;
206+ throw new Error ( " The HTML element with ID 'js-react-on-rails-context' has no textContent" ) ;
200207 }
201208
202209 return JSON . parse ( el . textContent ) ;
@@ -246,8 +253,7 @@ function unmount(el: Element): void {
246253 try {
247254 ReactDOM . unmountComponentAtNode ( domNode ) ;
248255 } catch ( e : any ) {
249- console . info ( `Caught error calling unmountComponentAtNode: ${ e . message } for domNode` ,
250- domNode , e ) ;
256+ console . info ( `Caught error calling unmountComponentAtNode: ${ e . message } for domNode` , domNode , e ) ;
251257 }
252258}
253259
@@ -281,23 +287,19 @@ function renderInit(): void {
281287 }
282288
283289 if ( turboInstalled ( ) ) {
284- debugTurbolinks (
285- 'USING TURBO: document added event listeners ' +
286- 'turbo:before-render and turbo:render.' ) ;
290+ debugTurbolinks ( 'USING TURBO: document added event listeners turbo:before-render and turbo:render.' ) ;
287291 document . addEventListener ( 'turbo:before-render' , reactOnRailsPageUnloaded ) ;
288292 document . addEventListener ( 'turbo:render' , reactOnRailsPageLoaded ) ;
289293 reactOnRailsPageLoaded ( ) ;
290294 } else if ( turbolinksVersion5 ( ) ) {
291295 debugTurbolinks (
292- 'USING TURBOLINKS 5: document added event listeners ' +
293- 'turbolinks:before-render and turbolinks:render.' ) ;
296+ 'USING TURBOLINKS 5: document added event listeners turbolinks:before-render and turbolinks:render.' ,
297+ ) ;
294298 document . addEventListener ( 'turbolinks:before-render' , reactOnRailsPageUnloaded ) ;
295299 document . addEventListener ( 'turbolinks:render' , reactOnRailsPageLoaded ) ;
296300 reactOnRailsPageLoaded ( ) ;
297301 } else {
298- debugTurbolinks (
299- 'USING TURBOLINKS 2: document added event listeners page:before-unload and ' +
300- 'page:change.' ) ;
302+ debugTurbolinks ( 'USING TURBOLINKS 2: document added event listeners page:before-unload and page:change.' ) ;
301303 document . addEventListener ( 'page:before-unload' , reactOnRailsPageUnloaded ) ;
302304 document . addEventListener ( 'page:change' , reactOnRailsPageLoaded ) ;
303305 }
@@ -308,12 +310,12 @@ function isWindow(context: Context): context is Window {
308310}
309311
310312function onPageReady ( callback : ( ) => void ) {
311- if ( document . readyState === " complete" ) {
313+ if ( document . readyState === ' complete' ) {
312314 callback ( ) ;
313315 } else {
314- document . addEventListener ( " readystatechange" , function onReadyStateChange ( ) {
315- onPageReady ( callback ) ;
316- document . removeEventListener ( " readystatechange" , onReadyStateChange ) ;
316+ document . addEventListener ( ' readystatechange' , function onReadyStateChange ( ) {
317+ onPageReady ( callback ) ;
318+ document . removeEventListener ( ' readystatechange' , onReadyStateChange ) ;
317319 } ) ;
318320 }
319321}
0 commit comments