Skip to content

Commit a1cc54c

Browse files
committed
Reformat clientStartup.ts
1 parent 61f7df8 commit a1cc54c

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

node_package/src/clientStartup.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ import type {
88
} from './types/index';
99

1010
import createReactOutput from './createReactOutput';
11-
import {isServerRenderHash} from './isServerRenderResult';
11+
import { isServerRenderHash } from './isServerRenderResult';
1212
import reactHydrateOrRender from './reactHydrateOrRender';
1313

1414
declare global {
1515
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;
1818
}
19+
1920
namespace NodeJS {
2021
interface Global {
21-
ReactOnRails: ReactOnRailsType;
22+
ReactOnRails: ReactOnRailsType;
2223
}
2324
}
2425
namespace Turbolinks {
@@ -67,7 +68,7 @@ function turboInstalled() {
6768
return false;
6869
}
6970

70-
function reactOnRailsHtmlElements(): HTMLCollectionOf<Element> {
71+
function reactOnRailsHtmlElements(): HTMLCollectionOf<Element> {
7172
return document.getElementsByClassName('js-react-on-rails-component');
7273
}
7374

@@ -80,7 +81,7 @@ function forEachReactOnRailsComponentInitialize(fn: (element: Element, railsCont
8081

8182
function initializeStore(el: Element, railsContext: RailsContext): void {
8283
const context = findContext();
83-
const name = el.getAttribute(REACT_ON_RAILS_STORE_ATTRIBUTE) || "";
84+
const name = el.getAttribute(REACT_ON_RAILS_STORE_ATTRIBUTE) || '';
8485
const props = (el.textContent !== null) ? JSON.parse(el.textContent) : {};
8586
const storeGenerator = context.ReactOnRails.getStoreGenerator(name);
8687
const store = storeGenerator(props, railsContext);
@@ -107,15 +108,15 @@ function delegateToRenderer(
107108
props: Record<string, string>,
108109
railsContext: RailsContext,
109110
domNodeId: string,
110-
trace: boolean
111+
trace: boolean,
111112
): boolean {
112113
const { name, component, isRenderer } = componentObj;
113114

114115
if (isRenderer) {
115116
if (trace) {
116117
console.log(`\
117118
DELEGATING TO RENDERER ${name} for dom node with id: ${domNodeId} with props, railsContext:`,
118-
props, railsContext);
119+
props, railsContext);
119120
}
120121

121122
(component as RenderFunction)(props, railsContext, domNodeId);
@@ -126,7 +127,7 @@ DELEGATING TO RENDERER ${name} for dom node with id: ${domNodeId} with props, ra
126127
}
127128

128129
function domNodeIdForEl(el: Element): string {
129-
return el.getAttribute('data-dom-id') || "";
130+
return el.getAttribute('data-dom-id') || '';
130131
}
131132

132133
/**
@@ -137,10 +138,10 @@ function domNodeIdForEl(el: Element): string {
137138
function render(el: Element, railsContext: RailsContext): void {
138139
const context = findContext();
139140
// 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') || '';
141142
const domNodeId = domNodeIdForEl(el);
142143
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';
144145

145146
try {
146147
const domNode = document.getElementById(domNodeId);
@@ -187,7 +188,7 @@ function parseRailsContext(): RailsContext | null {
187188
}
188189

189190
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');
191192
}
192193

193194
return JSON.parse(el.textContent);
@@ -208,7 +209,9 @@ export function reactOnRailsPageLoaded(): void {
208209
function unmount(el: Element): void {
209210
const domNodeId = domNodeIdForEl(el);
210211
const domNode = document.getElementById(domNodeId);
211-
if(domNode === null){return;}
212+
if (domNode === null) {
213+
return;
214+
}
212215
try {
213216
ReactDOM.unmountComponentAtNode(domNode);
214217
} catch (e: any) {
@@ -258,7 +261,7 @@ function renderInit(): void {
258261
}
259262
}
260263

261-
function isWindow (context: Window | NodeJS.Global): context is Window {
264+
function isWindow(context: Window | NodeJS.Global): context is Window {
262265
return (context as Window).document !== undefined;
263266
}
264267

0 commit comments

Comments
 (0)