-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
28 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,20 +14,44 @@ Hopefully it's clear how to port it to your application. | |
- Any browser magic like `<button>` defaulting to `type="submit"` isn't | ||
implemented, so be careful. [Read Domino for ideas/implementations][1] | ||
|
||
## Examples | ||
|
||
I've included two small examples that use the frontend directory "public/" which | ||
does some vanilla HTML JS work. Use `npm run build` to run them. | ||
|
||
``` | ||
$ npm run build | ||
> [email protected] build /home/today/_/work/softdom/example-webserver | ||
> node --unhandled-rejections=strict --experimental-loader ../web-root-loader.mjs index.js | ||
Koa server listening on 3000 | ||
Render: 9.250ms | ||
Fetch 'http://localhost:3000/data.txt': 32ms | ||
Koa server stopped | ||
Serialize: 6.544ms | ||
Written to: /home/today/_/work/softdom/public/indexSSR.html | ||
``` | ||
|
||
For an example of a full web application written in Sinuous/JSX/TS that uses SSR | ||
see https://gitlab.com/nthm/stayknit, specifically [its ssr/ folder][2]. | ||
|
||
## Notes | ||
|
||
SoftDOM uses `Object.seal()` to throw errors when your web app tries to write | ||
properties that don't exist, i.e `el.innerText = 'Text!'` will throw (read | ||
below for workaround). This saves you from silent bugs! | ||
|
||
Lets consider supporting an unimplemented method: innerText. [MDN][2] says it's | ||
Lets consider supporting an unimplemented method: innerText. [MDN][3] says it's | ||
"almost" the same as Node#textContent (which is implemented in SoftDOM) but is | ||
aware of how the text is rendered by the browser. Now imagine trying to | ||
implement innerText to pass [their example][3]. That would be very difficult. | ||
implement innerText to pass [their example][4]. That would be very difficult. | ||
|
||
You know the tradeoffs that work best for your use case. The easiest would be | ||
aliasing `innerText = this.textContent`. The hardest is reading and implementing | ||
the W3C spec. You can write something in between that works for you. Don't be | ||
scared to hack at the code ✨✨ | ||
|
||
[1]: https://github.com/fgnass/domino/blob/master/lib/htmlelts.js#L342 | ||
[2]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText | ||
[3]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText#Result | ||
[2]: https://gitlab.com/nthm/stayknit/tree/work/ssr | ||
[3]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText | ||
[4]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText#Result |