luwes / little-vdom Goto Github PK
View Code? Open in Web Editor NEW๐ผ 650B Virtual DOM - Use reactive JSX with minimal overhead
๐ผ 650B Virtual DOM - Use reactive JSX with minimal overhead
// Adapted and fixed bugs from little-vdom.js
// https://gist.github.com/developit/2038b141b31287faa663f410b6649a87
import { h, Fragment, render } from 'https://unpkg.com/@luwes/[email protected]/dist/little-vdom.js';
/** @jsx h */
// Components get passed (props, state, setState)
function Counter(props, { count = 0 }, update) {
const increment = () => update({ count: ++count });
return <button onclick={increment}>{count}</button>
}
function Since({ time }, state, update) {
setTimeout(update, 1000); // update every second
const ago = (Date.now() - time) / 1000 | 0;
return <Fragment><h1>Since: </h1><time>{ago}s ago</time></Fragment>
}
function App(props, {visible=true}, update) {
setTimeout(() => update({visible: false}), 3000)
return <div id="app">
<h1>Hello</h1>
{visible ? <Since time={Date.now()} /> : false}
<Counter />
</div>
}
render(
<App />,
document.body
);
update visible delay 3s, can not remove the dom
of children component Since
setTimeout(() => update({visible: false}), 3000)
This should ideally work, I couldn't find a solution right away.
This PR fixed the same bug in Preact: preactjs/preact#1515
Lines 376 to 407 in 3b1b149
useState
/useReducer
/useRef
/useMemo
/useEffect
/useLayoutEffect
/useCallback
/createContext
/useContext
)A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.