snout-jsx
v1.0.1
Published
Snout is a small React-like JSX-supportive framework
Maintainers
Readme
Snout
Snout is a React-like JSX-supportive framework written in typescript under 400 lines of code.
Why
- Because if I can't create it, that means I don't understand it (Richard Feynman, probably, idk)
- I never seem to use idle callback system for managing tasks, it was fun
- This project completes a trio of backend, data and frontend packages to create web applicaitons from scratch
How
- JSX bindings are in
jsx-runtime.ts-jsx,jsxsandjsxDEVfunctions are in essencecreateElementfunctions jsx-runtime.tsalso providesJSX.*declarations and a typeElementfor basic operations, but I recommend usingSnoutNode(ReactNodelookalike)Element's are built until a function component is encountered- When calling
render(also available onjsx-runtime.ts) vdom tree is parsed fully into fiber tree that handles what element to process next (chooses parent, child, sibling) by putting it intonextUnitOfWorkvariable. - There is a running task completion service
workLoopusing idle callback system - It takes
nextUnitOfWorktoperformUnitOfWork, where magic happens - In essence, DOM is created via
createDOMand children are reconsiled inreconsileChildren - Inside that function fiber tree is altered and
commitWorkis called when it's time to end task inperformUnitOfWork useStatehook is provided as a simple way to alter component state to see PoC rendering
Usage
- In
tsconfig.jsonalter following properties
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "snout"
}
}- Use just as React framework
import { render, useState } from "snout";
const App = () => {
const [count, setCount] = useState<number>(0);
return <h1 onClick={() => setCount(c => c + 1)}>{`You have clicked me, ${count} times!`}</h1>;
};
render(<App />, document.getElementById("app")!);Limitations
- Multiple text children are failing, use
{\`}` to mitigate this problem - Fragments are untested
useStateis the only hook provided- When using this framework,
...no interface 'JSX.IntrinsicAttributes' existserrors are possible (they are static-check only and do not forbid compliation and working)
