Giter Club home page Giter Club logo

indomitable's Introduction

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 <div>Hello world!</div>:

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`
	<article @article>
		<h2>Project: @title!</h2>
		<img src:@image>
		<span>Comments: @comments</span>
		<a href:@url target:@>View Project</a>
		<pre>The mouse coordinates are (@x, @y).</pre>
	</article>
`
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)
// <article>

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

console.log(view.outerHTML)
/*
<article>
	<h2>Project: My Project!</h2>
	<img src="https://picsum.photos/600/400">
	<span>Comments: 100</span>
	<a href="https://darryl-yeo.com" target="_blank">View Project</a>
	<pre>The mouse coordinates are (1, 2).</pre>
</article>
*/

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

indomitable's People

Contributors

darrylyeo avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

indomitable's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.