Wardic instances
A Wardic instance is a w made for a fixed list of Features. Its elements bring those Features wherever they render, and take their props alone: a prop of a Feature the list lacks is a type error that names the Feature.
// src/lib/wardic.ts
export const { w } = createWardic([domAnimation, layout])
<w.li layout whileHover={{ scale: 1.05 }} />With that instance, <w.li drag /> fails to compile: Type 'boolean' is not assignable to type 'NeedsFeature<"drag">'.
createWardic
createWardic(features) makes one. Call it once, in a module of its own, and import its w where you'd import the binding's.
| It takes | What happens |
|---|---|
| A Feature, a preset or a list of them, nested | Each is given at once: built in a provider the first time one of the instance's elements needs it. |
A load, () => import("./drag-feature").then((m) => m.drag) | It starts on the client the first time one of the instance's elements or wards is made, or one of its hooks is called, once whichever provider asks; if it fails, the next provider to ask loads it again. Its Features take effect as they arrive; nothing before is replayed. A server render loads nothing. |
The instance's elements also have the Features their WardicProvider and any LazyWardic above them give, and render under a strict one. The module that calls createWardic ships the Features it's given at once to every page that imports it, so a page that drags can have an instance of its own.
// src/lib/wardic-room.ts: hover at once, drag when the room first renders
export const { w } = createWardic([domAnimation, () => import("./drag-feature").then((m) => m.drag)])WardicInstance
WardicInstance<F> is what createWardic(features) returns for Features F. A preset counts as its Features, a nested list as its own, and a load (() => import(…)) as what it resolves to.
| Member | What it is |
|---|---|
w | Every form of w, typed to F: w.<tag>, w.create, and w.ward on Solid 2 or w.createWard on Solid 1. Solid 1's use:w takes every prop: Solid types a directive by its name, whatever instance it comes from. |
useAnimateLayout, createInstantLayoutTransition, createResetProjection | Only when F has layout, given at once or loaded: the layout hooks, typed as the ones the binding exports. |
On Solid 2, a ward from the instance's w.ward(), or the one its element hands to wardRef, is a Ward<C, F>: it hears settled and its Features' events alone. On an instance without drag, card.next("dragEnd") is a type error that names drag.
WardConfigOf
WardConfigOf<F> is the motion props of an instance with Features F: the base props and its Features'. A component that hands its motion props on takes them, and can pass them to the instance's elements or to any with more Features, a plain w.* included.
const Card = (props: WardConfigOf<typeof domAnimation> & { title: string }) => <w.article {...props}>{props.title}</w.article>A prop of another Feature isn't one of them, so <Card drag /> is a type error, though not one that names drag. With every Feature, WardConfigOf<typeof domMax> is the whole of the motion props.