Nanowire is a minimal DOM patcher for HTML-over-the-wire.
- Enclose the element to be updated in a
<nw-frame>
tag with a unique ID. - Give the following arguments to the
apply
function,- The DOM node or document that is the ancestor of the "nw-frame" tags to be updated,
- Text containing "nw-frame" tags surrounding updates.
The following HTML is displayed first,
<nw-frame id="frame">
Hello?
</nw-frame>
and then the following code is executed,
import { apply } from 'nanowire';
apply(document, '<nw-frame id="frame">Hello, World!</nw-frame>');
the result is as follows.
<nw-frame id="frame">
Hello, World!
</nw-frame>
You can apply server-side rendered HTML as updates.
fetch('your API').then(res => res.text()).then(text => apply(document, text));
The nanowire/client
module provides short hands for fetch and apply.
<script src="https://unpkg.com/nanowire/dist/client.js"></script>
<button onClick="nanowire.get('your API')">GET</button>
<button onClick="nanowire.post('your API', JSON.stringify(['request body']))">POST</button>
See the example.
# clone this repository and move inside.
$ cd example
$ yarn serve
MIT License(see LICENSE file).