An open API service indexing awesome lists of open source software.

https://github.com/darrylyeo/indomitable

Create, reference, and update HTML/DOM objects with ease. Verbose native JavaScript APIs shall never subdue you!
https://github.com/darrylyeo/indomitable

dom dom-api dom-manipulation es6-javascript html javascript javascript-framework

Last synced: about 1 year ago
JSON representation

Create, reference, and update HTML/DOM objects with ease. Verbose native JavaScript APIs shall never subdue you!

Awesome Lists containing this project

README

          

# inDOMitable.js

Create, reference, and update HTML/DOM objects with ease. Verbose native JavaScript APIs shall never subdue you!

---

The native JavaScript APIs for interfacing with the HTML Document Object Model (DOM) can be very verbose. Here is the code for generating `

Hello world!
`:

```
const div = document.createElement('div')
const content = document.createTextNode('Hello world!')
div.appendChild(content)
document.body.appendChild(div)
```

inDOMitable.js aims to make a lot of that simpler, without sacrificing performance. The framework defines a function, `h`, which you can pass "@"-annotated HTML. The result is an HTML tree that is ready to use, along with a `.state` object to access and update the annotated text nodes, elements and attributes.

```
const view = h`

Project: @title!



Comments: @comments
View Project
The mouse coordinates are (@x, @y).


`
document.body.appendChild(view)

view.state.title = 'My Project'
view.state.target = '_blank'
view.state({
comments: 100,
url: 'https://darryl-yeo.com',
image: 'https://picsum.photos/600/400',
x: 1,
y: 2
})

console.log(view.refs.article)
//

console.log(view.state.url)
// https://darryl-yeo.com

console.log(view.outerHTML)
/*

Project: My Project!



Comments: 100
View Project
The mouse coordinates are (1, 2).

*/

window.onmousemove = ({x, y}) =>
view.state({x, y})
```