diff --git a/README.md b/README.md new file mode 100644 index 0000000..e30b3c1 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +small utility for creating DOM trees from javascript arrays. + +to use, clone/submodule/subtree/whatever the `main` branch, and import `json_as_html` from `export.mjs`. + +to see a demo, or contribute, clone the `dev` branch. + +here's the demo array being used at the time of writing this: + +```javascript +[ + "div", + [ + ["id", "wrapper"], + ["class", "demo_div"], + ], + [ + ["h1", [], "header :)"], + ["p", [], "paragraph! meow"], + ["p", [], "another paragraph!! this is so cool"], + state => ["button", [ + ["onclick", _ => { + state.set("clicked", true); + render(); + }] + ], "it can even do buttons!"], + state => ["p", [], state.get("clicked") ? "clicked" : "not clicked"], + ], +] + +``` + +it assumes a function `render` which replaces the contents of the `` with the result of calling `json_as_html` with this array as argument. it also assumes a `Map` called `state`.