VideState
VideState is a state handler for Vide sources. You describe a component's states, and VideState changes its properties whenever the state changes. Vide creates the UI Instances. VideState only manages the values those Instances bind to, and it never creates Instances itself.
How it works
- Create a rule. A rule is the blueprint of a component: the properties it has and the states it can be in. It validates the values of every state.
- Create a handler. A handler is one instance of that component, made from the rule with its states and an initial state. Each handler keeps its own state.
- Bind its sources. The sources of a handler follow its active state, so you bind them to Vide properties.
- Change the state. Call
setStateand react with the handler's events and transitions.
What you get
- Checked values. Describe properties with VideState's own schemas, so you don't need a separate validation library. An invalid value is reported with the state and the field that caused it, instead of failing later in the UI.
- Types in your editor. The analyzer knows the type of every source of a handler. Annotate a table of states and it also reports a wrong value, a missing field, and a missing or misspelt state.
- Reusable components. One rule makes as many handlers as you need. Rules share schemas, give fields default values, extend each other, and carry tags.
- A guarded set of states. A rule can name the states a component may have and which state may follow which, and a handler tells you when it changes, enters, or leaves a state.
- Transitions. Fade the properties between states with an easing, a duration, a speed, and a delay for each connection, and different settings for particular state changes. A transition that is interrupted continues from where it was, so nothing jumps. Read the values in a callback, as Vide sources, or as one progress source.
- Curves, sequences, and stagger. Use the built-in easings or make your own bezier, spring, or bounce curve. Play several states in turn, or start a list of handlers one after another.
- Controls. Pause, resume, scale the speed of, or finish a transition, wait for it to finish, or change state instantly.
- Every handler. Act on all handlers at once, filtered by tags, rule, or state.
- A low cost. With a static rule, changing state costs about the same as writing plain Vide sources by hand, and a dynamic rule adds about a microsecond to check its sources. A handler builds only the features it uses, keeps about 4 KB, and is collected when you let go of it. A transition takes its own duration even when the frames are slow. The numbers are on the Performance page.
- Tools for real projects. A manual clock to test transitions at exact times, opt-in debug tools with a Vide debug view, and reduced motion for accessibility.
- One dependency. VideState needs only Vide. Its easings, schemas, and engine are also separate packages, if you want one part.
Continue with the Getting started guide, or read Why VideState for the reasons behind it.