0.1.2 • Published 8 years ago

update-element-children v0.1.2

Weekly downloads
2
License
ISC
Repository
github
Last release
8 years ago

update-element-children

Build Status

Unlike most other virtual doms, this one is intended to operate on the children of an existing HTMLElement.

Install:

npm i update-element-children

Examples:

Simple Example

/** @jsx h */
import {h, updateChildren} from 'update-element-children';

const root = document.getElementById('root');

updateChildren(root, null, <div>Test</div>);

Results in the following tree:

<div id="root">
	<div>Test</div>
</div>

Redux Example

/** @jsx h */
import {h, updateChildren} from 'update-element-children';
import {createStore} from 'redux';

const root = document.getElementById('root');
const store = createStore((state = 0, {type, payload}) => {
	if(type === 'TIME') return payload;
	return state;
});

let previousRender = null;
function render(state) {
	const timeStr = new Date(state).toLocaleTimeString();
	updateChildren(root, previousRender, [timeStr]);
	previousRender = currentRender;
}

store.subscribe(() => render(store.getState()));

setInterval(
	() => store.dispatch({
		type: 'TIME',
		payload: Date.now()
	}),
	1000
);

Results in the following tree:

<div id="root">11:20:06 AM</div>

Which changes every second to reflect the new time. A demo of this behavior can be found here.

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago