@@ -13,9 +13,9 @@ import type {
1313 AuthenticityHeaders ,
1414 Store ,
1515 StoreGenerator ,
16- ReactOnRailsOptions ,
1716} from './types/index.ts' ;
1817import reactHydrateOrRenderInternal from './reactHydrateOrRender.ts' ;
18+ import { resetOptions } from './options.ts' ;
1919
2020export { default as buildConsoleReplay } from './buildConsoleReplay.ts' ;
2121
@@ -25,22 +25,17 @@ declare global {
2525 /* eslint-enable no-var,vars-on-top,no-underscore-dangle */
2626}
2727
28+ // eslint-disable-next-line no-underscore-dangle
2829if ( globalThis . __REACT_ON_RAILS_LOADED__ ) {
2930 throw new Error ( `\
3031The ReactOnRails value exists in the ${ globalThis } scope, it may not be safe to overwrite it.
3132This could be caused by setting Webpack's optimization.runtimeChunk to "true" or "multiple," rather than "single."
3233Check your Webpack configuration. Read more at https://github.com/shakacode/react_on_rails/issues/1558.` ) ;
3334}
3435
36+ // eslint-disable-next-line no-underscore-dangle
3537globalThis . __REACT_ON_RAILS_LOADED__ = true ;
3638
37- const DEFAULT_OPTIONS = {
38- traceTurbolinks : false ,
39- turbo : false ,
40- } ;
41-
42- let options : ReactOnRailsOptions = { } ;
43-
4439// TODO: convert to re-exports if everything works fine
4540export function register ( components : Record < string , ReactComponentOrRenderFunction > ) : void {
4641 ComponentRegistry . register ( components ) ;
@@ -83,26 +78,6 @@ export function reactHydrateOrRender(
8378 return reactHydrateOrRenderInternal ( domNode , reactElement , hydrate ) ;
8479}
8580
86- export function setOptions ( newOptions : Partial < ReactOnRailsOptions > ) : void {
87- if ( typeof newOptions . traceTurbolinks !== 'undefined' ) {
88- options . traceTurbolinks = newOptions . traceTurbolinks ;
89-
90- // eslint-disable-next-line no-param-reassign
91- delete newOptions . traceTurbolinks ;
92- }
93-
94- if ( typeof newOptions . turbo !== 'undefined' ) {
95- options . turbo = newOptions . turbo ;
96-
97- // eslint-disable-next-line no-param-reassign
98- delete newOptions . turbo ;
99- }
100-
101- if ( Object . keys ( newOptions ) . length > 0 ) {
102- throw new Error ( `Invalid options passed to ReactOnRails.options: ${ JSON . stringify ( newOptions ) } ` ) ;
103- }
104- }
105-
10681export function reactOnRailsPageLoaded ( ) {
10782 return ClientStartup . reactOnRailsPageLoaded ( ) ;
10883}
@@ -127,10 +102,6 @@ export function authenticityHeaders(otherHeaders: Record<string, string> = {}):
127102// INTERNALLY USED APIs
128103// /////////////////////////////////////////////////////////////////////////////
129104
130- export function option < K extends keyof ReactOnRailsOptions > ( key : K ) : ReactOnRailsOptions [ K ] | undefined {
131- return options [ key ] ;
132- }
133-
134105export function getStoreGenerator ( name : string ) : StoreGenerator {
135106 return StoreRegistry . getStoreGenerator ( name ) ;
136107}
@@ -201,12 +172,9 @@ export function stores(): Map<string, Store> {
201172 return StoreRegistry . stores ( ) ;
202173}
203174
204- export function resetOptions ( ) : void {
205- options = { ...DEFAULT_OPTIONS } ;
206- }
207-
208175resetOptions ( ) ;
209176
210177ClientStartup . clientStartup ( ) ;
211178
212179export * from './types/index.ts' ;
180+ export * from './options.ts' ;
0 commit comments