Migration
Each section lists what to change or check when you upgrade to that version. The latest version is at the top. If you skip versions, follow the section of every version you pass, from the oldest to the newest. Only 0.3.0, 0.4.0, 0.7.0, 0.8.0, and 0.9.0 can need changes to your code, and 0.9.1 if you installed one of the inner packages on its own. How the speed and memory changed is on the Performance changes page.
0.9.1
Nothing breaks if you install idemandsky/videstate: the API and the require are the same.
VideState is one package again. videstate/core, videstate/schemas, and videstate/engine are now part of idemandsky/videstate and get no more releases. If you installed one of them on its own, install idemandsky/videstate instead and read the same functions from it: the easings and tween are at the top level, and the schema builders are in VideState.schemas.
embr add videstate/coreembr add idemandsky/videstate0.9.0
0.9.0 has one change to check: a handler made inside a Vide scope, such as a component, a Vide.root, or an effect, is now destroyed when that scope is cleaned up. Most code needs no change, and a Vide.cleanup(handler.destroy) you wrote yourself can stay or go. Only a handler that is made inside a scope and used after that scope is gone needs to move. Afterwards its setState raises setState cannot be called after destroy.
Make such a handler outside any scope, for example at the top of a module.
-- The handler is made inside the root, and kept after the root is destroyed.
const Vide = require("@packages/Vide")
const VideState = require("@VideState")
const schemas = VideState.schemas
const rules = VideState.rules
const ToastRule = rules.static(schemas.new({
transparency = schemas.float({ min = 0, max = 1 }),
}), { name = "Toast" })
local handler
const destroyRoot = Vide.root(function()
handler = ToastRule.new({
Hidden = { transparency = 1 },
Shown = { transparency = 0 },
}, "Hidden")
end)
destroyRoot()
handler.setState("Shown") -- Raises an error in 0.9.0.-- The handler is made outside the root, so the root does not destroy it.
const Vide = require("@packages/Vide")
const VideState = require("@VideState")
const schemas = VideState.schemas
const rules = VideState.rules
const ToastRule = rules.static(schemas.new({
transparency = schemas.float({ min = 0, max = 1 }),
}), { name = "Toast" })
const handler = ToastRule.new({
Hidden = { transparency = 1 },
Shown = { transparency = 0 },
}, "Hidden")
const destroyRoot = Vide.root(function()
-- Bind handler.sources here.
end)
destroyRoot()
handler.setState("Shown")0.8.0
0.8.0 has three breaking changes: the schema builders moved to VideState.schemas, the rule functions moved to VideState.rules (VideState.rule is now rules.dynamic and takes a rule schema), and VideState.extend is now rules.extendDynamic, which takes its extra fields as a rule schema too. Every rule needs the first two changes, and every call to extend the third.
Move the schema builders to VideState.schemas
Every field builder moved from the top level of VideState into VideState.schemas, next to the functions that make a rule schema. The old names are gone, so a call such as VideState.float() raises an error. Add schemas. to each one, or make a local alias.
const VideState = require("@VideState")
-- Before (0.7.0)
const ButtonRule = VideState.rule({
alpha = VideState.float({ min = 0, max = 1 }),
size = VideState.udim2(),
}, { name = "Button" })
-- After (0.8.0)
const schemas = VideState.schemas
const rules = VideState.rules
const ButtonRule = rules.dynamic(schemas.new({
alpha = schemas.float({ min = 0, max = 1 }),
size = schemas.udim2(),
}), { name = "Button" })The builders that moved are boolean, enum, float, integer, optional, union, string, table, record, color3, numberRange, numberSequence, colorSequence, udim, udim2, and vector2. Their arguments did not change.
Rename rule to rules.dynamic, and wrap the fields in a schema
VideState.rule is now VideState.rules.dynamic, so it can be told apart from the new rules.static. rules.dynamic takes a rule schema made with VideState.schemas.new instead of a plain table of fields. rule was removed in 0.8.0, so a call to it raises an error.
const VideState = require("@VideState")
const schemas = VideState.schemas
const rules = VideState.rules
-- Before
const ButtonRule = VideState.rule({ alpha = schemas.float() }, { name = "Button" })
-- After
const ButtonRule = rules.dynamic(schemas.new({ alpha = schemas.float() }), { name = "Button" })Rename extend to rules.extendDynamic, and pass a schema of extra fields
VideState.extend is now VideState.rules.extendDynamic, to match the new rules.extendStatic. It takes its extra fields as a rule schema too. A plain table of fields raises an error in 0.8.0.
const VideState = require("@VideState")
const schemas = VideState.schemas
const rules = VideState.rules
const ButtonRule = rules.dynamic(schemas.new({ alpha = schemas.float() }), { name = "Button" })
-- Before
const IconButtonRule = VideState.extend(ButtonRule, { iconColor = schemas.color3() }, { name = "IconButton" })
-- After
const IconButtonRule = rules.extendDynamic(ButtonRule, schemas.new({
iconColor = schemas.color3(),
}), { name = "IconButton" })What to check
| Change | Affects you when | What to do |
|---|---|---|
A state can leave out a field that has a default, so new raises no "missing source" error for it. | You relied on that error for a field you now give a default. | Nothing. A field with no default is still required in every state. |
| A schema checks a Vide source by reading its current value once. Before, a check inside your own Vide root also checked every later write to the source while the root lived. | You call a schema's parse on a source yourself and relied on it to reject a later write. | Check the value where you write it. Handlers are not affected, because they never kept that check. |
setState checks only the state it changes to. The state it leaves was checked when it was entered, and is not checked again, so a bad value written to one of its sources since then raises no error. | You relied on setState to catch a bad value in the state being left. | Nothing in most code. The state being entered is still checked. |
A transition takes its own duration when the frames are slow. Before, heavy frames (thousands of transitions at once, or slow onTransition callbacks) made every transition run slower than real time. | You tuned a duration on a slow device or a busy screen, where it ran longer than you set. | Check those durations. They now last exactly as long as you set. |
A handler makes its events, pause, transitions, and sequences the first time one is used, so the first onChange, onTransition, or animate of a handler costs a little more memory and time than a later one. | You measured the cost of one connection. | Nothing. A handler and its first connection together cost less than before. See Performance changes in 0.8.0. |
New in 0.8.0
None of these needs a change. They are there when you want them:
Handlers are faster and lighter:
setStatewith nothing connected takes about a tenth of the time, and a handler holds about a quarter of the memory. The numbers are in Performance changes in 0.8.0.VideState.schemas.withDefaultgives a field a default value, and a state that leaves the field out gets it.VideState.schemas.newmakes a rule schema, which one or more rules can share.VideState.schemas.withDefaultsgives defaults to several fields of a schema at once, andVideState.schemas.extendadds fields to a schema.VideState.rules.staticmakes a rule whose handlers take plain values that never change, which makes creating handlers about twice as fast, andrules.extendStaticbuilds on it.
0.7.0
0.7.0 has two breaking changes, both small. Everything else in your code runs as it is, because videstate still returns the whole API in one table.
What to change
| Change | Affects you when | What to do |
|---|---|---|
VideState.tweenSettings is now VideState.tween. | You check tween presets with tweenSettings. | Rename the call. It takes the same table and returns the same frozen copy. |
VideState.mergeTweenSettings was removed. | You build a variant of a preset with it. | Write the variant as a new tween call. |
const VideState = require("@VideState")
const Fast = VideState.tweenSettings({ duration = 0.15, easing = "quadOut" })
const FastBouncy = VideState.mergeTweenSettings(Fast, { easing = "backOut" })const VideState = require("@VideState")
const Fast = VideState.tween({ duration = 0.15, easing = "quadOut" })
const FastBouncy = VideState.tween({ duration = 0.15, easing = "backOut" })New in 0.7.0
None of these needs a change:
VideState.bouncemakes a bouncing-ball easing, and every custom easing haslerp.- VideState is now three packages,
videstate/core,videstate/schemas, andvidestate/engine. You can install one on its own, and each has its own version and changelog.
0.6.0
0.6.0 has no breaking changes. Code written for 0.5.1 runs as it is.
What changed
| Change | Affects you when | What to do |
|---|---|---|
VideState.tweenSettings and mergeTweenSettings are new. 0.7.0 renamed the first to tween and removed the second. | You keep tween presets in a config module. | Optional. Wrap a preset in them so a bad value fails when the module loads. |
debug.setFallbackWarnings is new. | A tween setting source returns a bad value without you noticing. | Optional. Turn it on while you develop. |
0.5.0
0.5.0 has no breaking changes. Code written for 0.4.0 runs as it is. This section lists the few changes that can show up in code that uses VideState in an unusual way.
What to check
| Change | Affects you when | What to do |
|---|---|---|
onTransition callbacks receive a fifth argument, round. | Your callback uses ... or counts its arguments. | Nothing, unless you forward every argument. A callback that lists four parameters works as before. |
A Handler has a new function, playSequence, and progress. | You wrote a mock or a wrapper that implements the Handler type yourself. | Add the two functions to it. |
setState can raise a new error when the rule has allowedTransitions. | You add allowedTransitions to an existing rule. | Check that no code changes between states the rule no longer lists. |
everyHandler lists handlers in the order they were created. | You depended on the order of an earlier version, which was not defined. | Nothing. The order is now the creation order. |
The Schema entry of the schemas guide no longer has parse. | You linked to /guide/schemas#parse. | Remove the link. parse still exists on a schema, but it is not part of the documented API. |
New in 0.5.0
None of these needs a change. They are there when you want them:
VideState.unionaccepts a value of either of two schemas.VideState.rules.extendDynamicmakes a rule from a base rule.allowedTransitionslimits which state can follow which.playSequenceplays several states in turn, andprogressgives the alpha of a transition as a source.bezierandeasingmake an easing of your own.setReducedMotionmakes every state change instant.- A
delayoption onsetStateand astaggeroption oneveryHandler.setState. - A manual clock for tests.
0.4.0
0.4.0 removed the options of a handler. A handler used to take default tween settings, and every onTransition connection inherited them. Now each connection has its own settings, in tweenDefault, and a setting it leaves out takes the built-in default: 0.25 seconds, linear, speed 1, no delay.
This is a breaking change. A third argument to new raises an error, and so does a tween setting at the top level of the options of onTransition, with a message that points to tweenDefault.
Before and after
The settings of the handler moved to the connections that need them. In these examples, ButtonRule is a rule, states is the table of Vide sources for each of its states, and button is the Instance that the component draws:
-- 0.3.0 and earlier
const handler = ButtonRule.new(states, "Idle", {
onTransition = {
duration = 0.15,
easing = "quadOut",
},
})
handler.onTransition(function(_, _, current)
button.BackgroundColor3 = current.backgroundColor
end)-- 0.4.0
const handler = ButtonRule.new(states, "Idle")
handler.onTransition(function(_, _, current)
button.BackgroundColor3 = current.backgroundColor
end, {
tweenDefault = {
duration = 0.15,
easing = "quadOut",
},
})The options that a single connection already passed also move inside tweenDefault. Here, callback is the function that onTransition calls on every frame:
-- 0.3.0 and earlier
handler.onTransition(callback, { duration = 0.3 })
-- 0.4.0
handler.onTransition(callback, {
tweenDefault = {
duration = 0.3,
},
})Steps
- Remove the third argument of every
newcall. - Put the settings that it held into the
tweenDefaultof eachonTransitioncall that relied on them. - Move the top-level
easing,duration,speed, anddelayof every connection intotweenDefault. - Remove
HandlerOptionsfrom your types. It no longer exists.
If many components used the same handler options, keep the settings in one module and pass them to every connection. See Tween config.
New in 0.4.0
- Ripple is no longer a dependency. VideState tweens values itself, so installing the package pulls one package fewer. The values are the same.
tweenOverridessets other tween settings for particular state changes.handler.animatereturns Vide sources that follow a transition, so you can bind a property to them instead of writing anonTransitioncallback.
0.3.0
0.3.0 renamed fastForward to scaleSpeed, because a speed below 1 slows a transition down. It also changed what the scale applies to. This is a breaking change.
Before and after
In both examples, handler is a handler made with rule.new.
-- 0.2.0
handler.fastForward({ speed = 4 })-- 0.3.0
handler.scaleSpeed({ speed = 4, once = true })| 0.2.0 | 0.3.0 |
|---|---|
handler.fastForward(options) | handler.scaleSpeed(options) |
FastForwardOptions | ScaleSpeedOptions |
| The speed applied to the running transition only. | The speed applies to every following transition, until you call scaleSpeed again. Pass once = true to apply it to the running transition only. |
Steps
- Rename every
fastForwardcall toscaleSpeed, andFastForwardOptionstoScaleSpeedOptions. - Add
once = trueto each call that should affect only the running transition, which is whatfastForwarddid. - If a call should keep the scale for later transitions, leave
onceout.
New in 0.3.0
VideState.everyHandler acts on every handler at once, with filters by tag, rule, and state. Nothing in it replaces an old function, so you do not need to change anything to use it later.