@@ -7,24 +7,12 @@ import React from 'react';
77import _ from 'underscore' ;
88import deps from 'dependencies' ;
99import 'externals' ;
10- import { createRoot , hydrateRoot } from 'react-dom/client' ;
1110
12- /**
13- * -----------------------------------------------------------------------------
14- * @function App()
15- * @description Scan DOM for <Component> elements and render React components
16- * inside of them.
17- * -----------------------------------------------------------------------------
18- */
19- export const App = async ( ) => {
11+ export const Loader = async ( ) => { } ;
12+
13+ const loadFramework = async ( ) => {
2014 console . log ( 'Loading Core SDK' ) ;
21- const {
22- default : Reactium ,
23- hookableComponent,
24- isBrowserWindow,
25- Zone,
26- AppContexts,
27- } = await import ( 'reactium-core/sdk' ) ;
15+ const { default : Reactium } = await import ( 'reactium-core/sdk' ) ;
2816
2917 console . log ( 'Initializing Application Hooks' ) ;
3018
@@ -40,8 +28,6 @@ export const App = async () => {
4028 await Reactium . Hook . run ( 'sdk-init' , Reactium ) ;
4129 Reactium . Hook . runSync ( 'sdk-init' , Reactium ) ;
4230
43- const context = { } ;
44-
4531 /**
4632 * @api {Hook } init init
4733 * @apiName init
@@ -102,96 +88,97 @@ export const App = async () => {
10288 * @apiGroup Hooks
10389 */
10490 await Reactium . Hook . run ( 'plugin-ready' ) ;
91+ } ;
10592
106- if ( isBrowserWindow ( ) ) {
107- /**
108- * @api {Hook } component-bindings component-bindings
109- * @apiName component-bindings
110- * @apiDescription Called after plugin and routing initialization to define element and dynamic component for
111- one-off component bindings to the DOM. e.g. In development mode, used to render Redux Dev tools.
112- async only - used in front-end application only
113- * @apiParam {Object} context context.bindPoints MUST be an array of binding objects after this hook is called
114- * @apiParam (binding) {HTMLElement} the DOM element to bind to (e.g. document.getElementById('my-element'))
115- * @apiParam (binding) {String} string matching a React component module in one of the Reactium built-in webpack contexts
116- (src/app/components or src/app/components/common-ui) e.g. 'DevTools' maps to src/app/components/DevTools
117- * @apiGroup Hooks
118- */
119- const { bindPoints } = await Reactium . Hook . run ( 'component-bindings' ) ;
120-
121- /**
122- * @api {Hook } app-bindpoint app-bindpoint
123- * @apiName app-bindpoint
124- * @apiDescription Called after plugin and routing initialization to define the DOM element used for mounting the Single-Page application (SPA).
125- By default, the application will bind to `document.getElementById('router')`, but this can be changed with this hook. This is related to the HTML
126- template artifacts left by the server-side `Server.AppBindings` hook.
127- async only - used in front-end application only
128- * @apiParam {Object} context context.appElement MUST be an HTMLElement where your React appliation will bind to the DOM.
129- * @apiParam (appElement) {HTMLElement} the DOM element to bind to - by default `document.getElementById('router')`.
130- * @apiGroup Hooks
131- */
132- const { appElement } = await Reactium . Hook . run ( 'app-bindpoint' ) ;
133-
134- /**
135- * @api {Hook } app-context-provider app-context-provider
136- * @apiName app-context-provider
137- * @apiDescription Called after app-bindpoint to define any React context providers, using the [Reactium.AppContext](#api-Reactium-Reactium.AppContext) registry.
138- * @apiGroup Hooks
139- */
140- await Reactium . Hook . run ( 'app-context-provider' ) ;
141-
142- /**
143- * @api {Hook } app-router app-router
144- * @apiName app-router
145- * @apiDescription Called after app-context-provider to define the registered Router component (i.e. `Reactium.Component.register('Router'...)`).
146- After this hook, the ReactDOM bindings will actually take place.
147- async only - used in front-end application only
148- * @apiGroup Hooks
149- */
150- await Reactium . Hook . run ( 'app-router' ) ;
151-
152- const Router = hookableComponent ( 'Router' ) ;
153-
154- // Render the React Components
155- if ( bindPoints . length > 0 ) {
156- bindPoints . forEach ( item =>
157- createRoot ( item . element ) . render (
158- < AppContexts > { item . component } </ AppContexts > ,
159- ) ,
160- ) ;
161- }
93+ /**
94+ * -----------------------------------------------------------------------------
95+ * @function App()
96+ * @description Scan DOM for <Component> elements and render React components
97+ * inside of them.
98+ * -----------------------------------------------------------------------------
99+ */
100+ export const App = async ( ) => {
101+ const {
102+ default : Reactium ,
103+ hookableComponent,
104+ Zone,
105+ AppContexts,
106+ } = await import ( 'reactium-core/sdk' ) ;
107+
108+ await loadFramework ( ) ;
109+
110+ /**
111+ * @api {Hook } component-bindings component-bindings
112+ * @apiName component-bindings
113+ * @apiDescription Called after plugin and routing initialization to define element and dynamic component for
114+ one-off component bindings to the DOM. e.g. In development mode, used to render Redux Dev tools.
115+ async only - used in front-end application only
116+ * @apiParam {Object} context context.bindPoints MUST be an array of binding objects after this hook is called
117+ * @apiParam (binding) {HTMLElement} the DOM element to bind to (e.g. document.getElementById('my-element'))
118+ * @apiParam (binding) {String} string matching a React component module in one of the Reactium built-in webpack contexts
119+ (src/app/components or src/app/components/common-ui) e.g. 'DevTools' maps to src/app/components/DevTools
120+ * @apiGroup Hooks
121+ */
122+ const { bindPoints } = await Reactium . Hook . run ( 'component-bindings' ) ;
162123
163- // ensure router DOM Element is on the page
164- if ( appElement ) {
165- /**
166- * @api {Hook } app-boot-message app-boot-message
167- * @apiName app-boot-message
168- * @apiDescription Called during application binding, this minor hook will allow you to
169- change the format of the of the front-end Javascript console message indicating application start.
170- async only - used in front-end application only
171- * @apiGroup Hooks
172- */
173- const { message = [ ] } = await Reactium . Hook . run (
174- 'app-boot-message' ,
175- ) ;
176- console . log ( ...message ) ;
177-
178- createRoot ( appElement ) . render (
179- < AppContexts >
180- < Zone zone = 'reactium-provider' />
181- < Router history = { Reactium . Routing . history } />
182- < Zone zone = 'reactium-provider-after' />
183- </ AppContexts > ,
184- ) ;
185-
186- /**
187- * @api {Hook } app-ready app-ready
188- * @apiDescription The final hook run after the front-end application has bee bound or hydrated. After this point,
189- the all hooks are runtime hooks.
190- * @apiName app-ready
191- * @apiGroup Hooks
192- */
193- _ . defer ( ( ) => Reactium . Hook . run ( 'app-ready' ) ) ;
124+ /**
125+ * @api {Hook } app-context-provider app-context-provider
126+ * @apiName app-context-provider
127+ * @apiDescription Called after app-bindpoint to define any React context providers, using the [Reactium.AppContext](#api-Reactium-Reactium.AppContext) registry.
128+ * @apiGroup Hooks
129+ */
130+ await Reactium . Hook . run ( 'app-context-provider' ) ;
131+
132+ // Render the React Components
133+ if ( bindPoints . length > 0 ) {
134+ const { createRoot } = await import ( 'react-dom/client' ) ;
135+
136+ console . log ( 'Binding components.' ) ;
137+ for ( const { type, Component, Element } of bindPoints ) {
138+ if ( type === 'App' ) {
139+ /**
140+ * @api {Hook } app-router app-router
141+ * @apiName app-router
142+ * @apiDescription Called after app-context-provider to define the registered Router component (i.e. `Reactium.Component.register('Router'...)`).
143+ After this hook, the ReactDOM bindings will actually take place.
144+ async only - used in front-end application only
145+ * @apiGroup Hooks
146+ */
147+ await Reactium . Hook . run ( 'app-router' ) ;
148+
149+ const Router = hookableComponent ( 'Router' ) ;
150+ const { message = [ ] } = await Reactium . Hook . run (
151+ 'app-boot-message' ,
152+ ) ;
153+
154+ console . log ( ...message ) ;
155+
156+ createRoot ( Element ) . render (
157+ < AppContexts >
158+ < Zone zone = 'reactium-provider' />
159+ < Router history = { Reactium . Routing . history } />
160+ < Zone zone = 'reactium-provider-after' />
161+ </ AppContexts > ,
162+ ) ;
163+
164+ /**
165+ * @api {Hook } app-ready app-ready
166+ * @apiDescription The final hook run after the front-end application has bee bound or hydrated. After this point,
167+ the all hooks are runtime hooks.
168+ * @apiName app-ready
169+ * @apiGroup Hooks
170+ */
171+ } else {
172+ // createRoot(Element).render(<Component />);
173+ createRoot ( Element ) . render (
174+ < AppContexts >
175+ < Component />
176+ </ AppContexts > ,
177+ ) ;
178+ }
194179 }
180+
181+ _ . defer ( ( ) => Reactium . Hook . run ( 'app-ready' ) ) ;
195182 }
196183} ;
197184
0 commit comments