@@ -72,7 +72,7 @@ adheres to the following interface:
7272 }
7373
7474 type bind = (node : HTMLElement , context : LayoutContext ) => ({
75- render(component : any , props : Object , children : Array <any >): void ;
75+ render(component : any , props : Object , childModels : Array <any >): void ;
7676 unmount(): void ;
7777 });
7878
@@ -88,7 +88,10 @@ adheres to the following interface:
8888 - ``props `` is an object containing attributes and callbacks for the given
8989 ``component ``.
9090
91- - ``children `` is an array of unrendered VDOM elements.
91+ - ``childModels `` is an array of unrendered VDOM elements. Passing them in this raw
92+ form allows for other frameworks besides react to render them as needed. If you
93+ are using react, you can just use the ``idom-client-react `` library to process
94+ them. See :ref: `Distributing Javascript via PyPI ` for an example usage.
9295
9396The interface returned by ``bind() `` can be thought of as being similar to that of
9497React.
@@ -215,12 +218,26 @@ To start, let's take a look at the file structure we'll be building:
215218
216219 import * as React from " react" ;
217220 import * as ReactDOM from " react-dom" ;
221+ import { LayoutConfigContext , elementChildren } from " idom-client-react" ;
222+
223+ export function bind (node , config ) {
224+ return {
225+ render : (component , props , childModels ) =>
226+ ReactDOM .render (createElement (config, component, props, childModels), node),
227+ unmount : () => ReactDOM .unmountComponentAtNode (node),
228+ };
229+ }
218230
219- // exports required to interface with IDOM
220- export const createElement = (component , props ) =>
221- React .createElement (component, props);
222- export const renderElement = ReactDOM .render ;
223- export const unmountElement = ReactDOM .unmountComponentAtNode ;
231+ function createElement (config , component , props , childModels ) {
232+ // Render child models with idom-client-react
233+ return React .createElement (
234+ LayoutConfigContext .Provider ,
235+ { value: config },
236+ React .createElement (
237+ component, props, ... elementChildren (children)
238+ )
239+ )
240+ }
224241
225242 // exports for your components
226243 export YourFirstComponent (props ) {...};
@@ -248,6 +265,7 @@ Your ``package.json`` should include the following:
248265 " dependencies" : {
249266 " react" : " ^17.0.1" ,
250267 " react-dom" : " ^17.0.1" ,
268+ " idom-client-react" : " ^0.8.5" ,
251269 ...
252270 },
253271 ...
0 commit comments