@@ -11,40 +11,69 @@ A light-weight DOM Renderer supports [Web components][1] standard & [TypeScript]
1111
1212## Feature
1313
14- - input: ** Virtual DOM** object in ** JSX** syntax
15- - output: ** DOM** object or ** XML** string of ** HTML** , ** SVG** & ** MathML** languages
14+ - input: [ Virtual DOM] [ 7 ] object in [ JSX] [ 8 ] syntax
15+ - output: [ DOM] [ 9 ] object or [ XML] [ 10 ] string of [ HTML] [ 11 ] , [ SVG] [ 12 ] & [ MathML] [ 13 ] languages
16+ - run as: ** Sync** , [ Async] [ 14 ] , [ Generator] [ 15 ] functions & [ Readable streams] [ 16 ]
1617
1718## Usage
1819
1920### JavaScript
2021
22+ #### Sync Rendering
23+
2124``` js
22- import { DOMRenderer } from ' dom-renderer' ;
25+ import { DOMRenderer , VNode } from ' dom-renderer' ;
2326
2427const newVNode = new DOMRenderer ().patch (
25- {
28+ new VNode ( {
2629 tagName: ' body' ,
2730 node: document .body
28- },
29- {
31+ }) ,
32+ new VNode ( {
3033 tagName: ' body' ,
3134 children: [
32- {
35+ new VNode ( {
3336 tagName: ' a' ,
3437 props: { href: ' https://idea2.app/' },
3538 style: { color: ' red' },
36- children: [{ text: ' idea2app' }]
37- }
39+ children: [new VNode ( { text: ' idea2app' }) ]
40+ })
3841 ]
39- }
42+ })
4043);
41-
4244console .log (newVNode);
4345```
4446
47+ #### Async Rendering (experimental)
48+
49+ ``` diff
50+ import { DOMRenderer, VNode } from 'dom-renderer';
51+
52+ - const newVNode = new DOMRenderer().patch(
53+ + const newVNode = new DOMRenderer().patchAsync(
54+ new VNode({
55+ tagName: 'body',
56+ node: document.body
57+ }),
58+ new VNode({
59+ tagName: 'body',
60+ children: [
61+ new VNode({
62+ tagName: 'a',
63+ props: { href: 'https://idea2.app/' },
64+ style: { color: 'red' },
65+ children: [new VNode({ text: 'idea2app' })]
66+ })
67+ ]
68+ })
69+ );
70+ - console.log(newVNode);
71+ + newVNode.then(console.log);
72+ ```
73+
4574### TypeScript
4675
47- [ ![ Edit DOM Renderer example] ( https://codesandbox.io/static/img/play-codesandbox.svg )] [ 7 ]
76+ [ ![ Edit DOM Renderer example] ( https://codesandbox.io/static/img/play-codesandbox.svg )] [ 17 ]
4877
4978#### ` tsconfig.json `
5079
@@ -59,6 +88,8 @@ console.log(newVNode);
5988
6089#### ` index.tsx `
6190
91+ ##### Sync Rendering
92+
6293``` tsx
6394import { DOMRenderer } from ' dom-renderer' ;
6495
@@ -67,10 +98,26 @@ const newVNode = new DOMRenderer().render(
6798 idea2app
6899 </a >
69100);
70-
71101console .log (newVNode );
72102```
73103
104+ ##### Async Rendering (experimental)
105+
106+ ``` diff
107+ import { DOMRenderer } from 'dom-renderer';
108+
109+ const newVNode = new DOMRenderer().render(
110+ <a href="https://idea2.app/" style={{ color: 'red' }}>
111+ idea2app
112+ - </a>
113+ + </a>,
114+ + document.body,
115+ + 'async'
116+ );
117+ - console.log(newVNode);
118+ + newVNode.then(console.log);
119+ ```
120+
74121### Node.js & Bun
75122
76123#### ` view.tsx `
@@ -105,25 +152,35 @@ createServer((request, response) => {
105152
106153### Web components
107154
108- [ ![ Edit MobX Web components] ( https://codesandbox.io/static/img/play-codesandbox.svg )] [ 8 ]
155+ [ ![ Edit MobX Web components] ( https://codesandbox.io/static/img/play-codesandbox.svg )] [ 18 ]
109156
110157## Original
111158
112159### Inspiration
113160
114- [ ![ SnabbDOM] ( https://github.com/snabbdom.png )] [ 9 ]
161+ [ ![ SnabbDOM] ( https://github.com/snabbdom.png )] [ 19 ]
115162
116163### Prototype
117164
118- [ ![ Edit DOM Renderer] ( https://codesandbox.io/static/img/play-codesandbox.svg )] [ 10 ]
165+ [ ![ Edit DOM Renderer] ( https://codesandbox.io/static/img/play-codesandbox.svg )] [ 20 ]
119166
120167[ 1 ] : https://www.webcomponents.org/
121168[ 2 ] : https://www.typescriptlang.org/
122169[ 3 ] : https://libraries.io/npm/dom-renderer
123170[ 4 ] : https://github.com/EasyWebApp/DOM-Renderer/actions/workflows/main.yml
124171[ 5 ] : https://nodei.co/npm/dom-renderer/
125172[ 6 ] : https://gitpod.io/?autostart=true#https://github.com/EasyWebApp/DOM-Renderer
126- [ 7 ] : https://codesandbox.io/s/dom-renderer-example-pmcsvs?autoresize=1&expanddevtools=1&fontsize=14&hidenavigation=1&module=%2Fsrc%2Findex.tsx&theme=dark
127- [ 8 ] : https://codesandbox.io/s/mobx-web-components-pvn9rf?autoresize=1&fontsize=14&hidenavigation=1&module=%2Fsrc%2FWebComponent.ts&moduleview=1&theme=dark
128- [ 9 ] : https://github.com/snabbdom/snabbdom
129- [ 10 ] : https://codesandbox.io/s/dom-renderer-pglxkx?autoresize=1&expanddevtools=1&fontsize=14&hidenavigation=1&module=%2Fsrc%2Findex.ts&theme=dark
173+ [ 7 ] : https://en.wikipedia.org/wiki/Virtual_DOM
174+ [ 8 ] : https://facebook.github.io/jsx/
175+ [ 9 ] : https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model
176+ [ 10 ] : https://developer.mozilla.org/en-US/docs/Web/XML
177+ [ 11 ] : https://developer.mozilla.org/en-US/docs/Web/HTML
178+ [ 12 ] : https://developer.mozilla.org/en-US/docs/Web/SVG
179+ [ 13 ] : https://developer.mozilla.org/en-US/docs/Web/MathML
180+ [ 14 ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function
181+ [ 15 ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*
182+ [ 16 ] : https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
183+ [ 17 ] : https://codesandbox.io/s/dom-renderer-example-pmcsvs?autoresize=1&expanddevtools=1&fontsize=14&hidenavigation=1&module=%2Fsrc%2Findex.tsx&theme=dark
184+ [ 18 ] : https://codesandbox.io/s/mobx-web-components-pvn9rf?autoresize=1&fontsize=14&hidenavigation=1&module=%2Fsrc%2FWebComponent.ts&moduleview=1&theme=dark
185+ [ 19 ] : https://github.com/snabbdom/snabbdom
186+ [ 20 ] : https://codesandbox.io/s/dom-renderer-pglxkx?autoresize=1&expanddevtools=1&fontsize=14&hidenavigation=1&module=%2Fsrc%2Findex.ts&theme=dark
0 commit comments