Optionalvalue: ConstraintSource<T>
The initial value, a function to compute it, or a constraint to follow
Optionaloptions: ConstraintOptions<NoInfer<T>>
How the value is computed and tracked
Math.abs(this)
this + args[0] + args[1] + .... Also concatenates strings, which is handy for units.
false if this or any of args is falsy; otherwise the last value. Evaluation stops at the
first falsy value (so, for example, cjs(false).and(a) never reads a).
Math.ceil(this)
e to the power of this, Math.exp(this)
Math.floor(this)
Get the current value of this constraint, recomputing it first if it is invalid.
OptionalautoAddOutgoing: boolean
Whether a constraint that is computing its value right now should
start depending on this one (default: true)
OptionalgetterArg: unknown
Passed as the second argument to this constraint's getter function, if it recomputes
Inline if, like this ? trueValue : otherValue.
Change this constraint's value depending on the state of an FSM.
For each state name, the value this constraint should have in that state
Mark this constraint's value as invalid, so that it is recomputed the next time it's read. Anything that depends on it is invalidated too.
Whether this constraint's cached value is up to date. An invalid value is only recomputed
when it's next read (for example, with .get()).
The natural logarithm, Math.log(this)
The largest of this and args: Math.max(this, ...args)
The smallest of this and args: Math.min(this, ...args)
Removes the most recently added listener for callback. If thisArg is given, only a
listener that was added with that thisArg is removed.
OptionalthisArg: unknownCall callback when this constraint's value is invalidated. If it is invalidated several
times before listeners run (for example, in a cjs.wait() batch), callback is only called once.
OptionalthisArg: unknown
The this for callback (default: the global object)
Arguments to pass to callback
Like onChange, but listeners with a higher priority are called before those with a lower
one (or none).
OptionalthisArg: unknownThe first truthy value out of this and args, or false if none are. Evaluation stops at
the first truthy value (so, for example, cjs(true).or(b) never reads b).
Signal that this constraint's value will be computed later (for example, asynchronously).
Until resumeGetter is called, get() returns temporaryValue. Call this from inside the
constraint's getter function.
OptionaltemporaryValue: unknownA property of this constraint's value, like this[names[0]][names[1]]....
Math.round(this)
Change the value of this constraint. Anything that depends on it is invalidated.
The new value, a function to compute it, or a constraint to follow
Optionaloptions: { silent?: boolean }
silent: true updates the value without invalidating anything that depends on it
Change how this constraint's value is computed (see ConstraintOptions).
Change how this constraint's value is computed (see ConstraintOptions).
Math.sqrt(this)
Math.tan(this)
parseFloat(this)
Note: the preferred way to create a constraint is with
cjs(value)orcjs.constraint(value).A constraint communicates with the constraint solver to store and maintain a value. Its value can be a plain value, a function that computes it (whose dependencies are tracked automatically), or another constraint to follow.
Example