@loom-js/core
v0.22.2
Published
A reactive, component-driven, JavaScript framework.
Maintainers
Readme
A reactive components-first JavaScript framework.
Feature Highlights
- Micro-updates on rerenders - updates are made at the attribute & node-levels.
- Self-cleanup leveraging native JS garbage collection &
WeakMapto release dead nodes from memory. - Reactivity to rerender any number of components used within a component template - see Activities.
- Tagged Templates for performant processing of component templates - see Components.
- Custom elements (
defineElement) - consume loom components from any page as<some-element>- see Custom Elements. - Client-side Routing for dynamic rendering of components based on
Locationdata - see Routing. - Lazy-loading of routes & content (
lazyImport), tracked by the settlement signal - see Lazy Imports. - Server rendering (
@loom-js/core/server) - render to an HTML string for SSR & SSG through the same code path the browser runs - see Server Rendering. - Client hydration (
hydrate) - invisible takeover of pre-rendered pages: one atomic swap once the app has settled, no content flashes - see Client Hydration. - Dehydrated state (
resource→dehydrate→primeResources) - hand the server's fetched data to the client, so a primed hydration never refetches - see Dehydrated State. - 0 Dependencies (you're welcome)
- Typescript Types included.
Create an app
npm create @loom-js@latest my-appA standalone app that builds with @loom-js/build, server-first and TypeScript by default. See Getting Started for the choices.
Install
npm i @loom-js/core
yarn add @loom-js/core
pnpm add @loom-js/coreInclusion
import * as Loom from '@loom-js/core';Server rendering lives in its own entry:
import { renderToString } from '@loom-js/core/server';Quick Example
A component is a tagged template. Define one, then mount it with init.
import { component, init } from '@loom-js/core';
interface ButtonProps {
label: string;
type: string;
}
export const Button = component<ButtonProps>(
(html, props) => html`
<button type="${props.type}">${props.label}</button>
`
);
init({
app: Button({ label: 'Save', type: 'button' }),
root: document.body
});Documentation
For AI agents: the whole manual is one markdown file, llms-full.txt, with a topic index at llms.txt. This package ships the same manual for its own version as llms-full.txt.
The full documentation lives at loom-js-docs.vercel.app. The topics are ordered as a learning path:
Onboarding
- Getting Started
- Bootstrapping - mounting an app with
init. - Configuration -
globalConfig&appendEvents.
Templating
- Components - templates, props, life-cycle hooks, refs.
- Element Syntax - composing components in markup, slots, keys.
- Fragments - templates with more than one root node.
- Custom Elements -
defineElement, light & shadow DOM.
Reactivity
- Activities - state, effects, transforms, the settlement signal.
- Routing -
createRoutes, guards, hash navigation. - Lazy Imports -
lazyImport&lazyContent.
Server-first
- Server Rendering -
renderToString, SSR & SSG. - Client Hydration -
hydrate&settled. - Dehydrated State -
resource,dehydrate,primeResources.
Reference
- Diagnostics - warnings & debug logging.
Recognition
Thanks go out to Andrea Giammarchi for providing the algorithm that made this solution possible. It is also at the core of hyper(HTML), a light & fast virtual DOM alternative that Andrea created and maintains.
