Sprites.Logic
Boolean logic over reactive values. Each combinator reads its arguments and returns a reactive value that follows them, so a condition built from several values stays live and composes with the reactive structure.
- Sprites.Logic.And
- Sprites.Logic.Equals
- Sprites.Logic.Greater
- Sprites.Logic.Less
- Sprites.Logic.Not
- Sprites.Logic.Or
- Sprites.Logic.Select
Sprites.Logic.And Sprites.Reactive.Value
Sprites.Logic.And(...args)
True when every argument is true. With no arguments it is true. Each argument is a constant or a reactive value, so the result follows every one.
| Input | Type | Description |
|---|---|---|
...args | Any or Sprites.Reactive.Value | The conditions to combine, each read with Get. |
Returns a read-only Sprites.Reactive.Value, true while every argument is true.
const a = Sprites.Reactive.Value(true);
const b = Sprites.Reactive.Value(false);
const both = Sprites.Logic.And(a, b);
Sprites.Ui.Input.Checkbox(a);
Sprites.Ui.Input.Checkbox(b);
Sprites.Ui.Dom.Text(' both = ', both);
Sprites.Logic.Equals Sprites.Reactive.Value
Sprites.Logic.Equals(a, b)
True when two values are equal by ===. Either may be a constant or a reactive value, so the result follows both.
| Input | Type | Description |
|---|---|---|
a | Any or Sprites.Reactive.Value | The first value. |
b | Any or Sprites.Reactive.Value | The second value. |
Returns a read-only Sprites.Reactive.Value, true while the two values are equal.
const tool = Sprites.Reactive.Value('move');
const moving = Sprites.Logic.Equals(tool, 'move');
Sprites.Ui.Input.Dropdown(tool, () => {
Sprites.Ui.Input.Option('move', 'Move');
Sprites.Ui.Input.Option('draw', 'Draw');
});
Sprites.Ui.Dom.Text(' moving = ', moving);
Sprites.Logic.Greater Sprites.Reactive.Value
Sprites.Logic.Greater(a, b)
True when a is greater than b. Either may be a constant or a reactive value, so the result follows both.
| Input | Type | Description |
|---|---|---|
a | Number or Sprites.Reactive.Value | The value on the left of the comparison. |
b | Number or Sprites.Reactive.Value | The value on the right of the comparison. |
Returns a read-only Sprites.Reactive.Value, true while a is greater than b.
const score = Sprites.Reactive.Value(7);
const pass = Sprites.Logic.Greater(score, 5);
Sprites.Ui.Input.Number(score);
Sprites.Ui.Dom.Text(' pass = ', pass);
Sprites.Logic.Less Sprites.Reactive.Value
Sprites.Logic.Less(a, b)
True when a is less than b. Either may be a constant or a reactive value, so the result follows both.
| Input | Type | Description |
|---|---|---|
a | Number or Sprites.Reactive.Value | The value on the left of the comparison. |
b | Number or Sprites.Reactive.Value | The value on the right of the comparison. |
Returns a read-only Sprites.Reactive.Value, true while a is less than b.
const level = Sprites.Reactive.Value(3);
const low = Sprites.Logic.Less(level, 5);
Sprites.Ui.Input.Number(level);
Sprites.Ui.Dom.Text(' low = ', low);
Sprites.Logic.Not Sprites.Reactive.Value
Sprites.Logic.Not(a)
The reactive negation of one condition: true when the value is false.
| Input | Type | Description |
|---|---|---|
a | Any or Sprites.Reactive.Value | The condition to negate. |
Returns a read-only Sprites.Reactive.Value, true while the value is false.
const on = Sprites.Reactive.Value(true);
const off = Sprites.Logic.Not(on);
Sprites.Ui.Input.Checkbox(on);
Sprites.Ui.Dom.Text(' off = ', off);
Sprites.Logic.Or Sprites.Reactive.Value
Sprites.Logic.Or(...args)
True when any argument is true. With no arguments it is false. Each argument is a constant or a reactive value, so the result follows every one.
| Input | Type | Description |
|---|---|---|
...args | Any or Sprites.Reactive.Value | The conditions to combine, each read with Get. |
Returns a read-only Sprites.Reactive.Value, true while any argument is true.
const a = Sprites.Reactive.Value(false);
const b = Sprites.Reactive.Value(false);
const either = Sprites.Logic.Or(a, b);
Sprites.Ui.Input.Checkbox(a);
Sprites.Ui.Input.Checkbox(b);
Sprites.Ui.Dom.Text(' either = ', either);
Sprites.Logic.Select Sprites.Reactive.Value
Sprites.Logic.Select(condition, whenTrue, whenFalse)
One of two values by a condition: whenTrue while it holds, else whenFalse. The reactive form of a ternary, so a composite chooses a value with no raw if. Each argument is a constant or a reactive value, so the result follows them.
| Input | Type | Description |
|---|---|---|
condition | Any or Sprites.Reactive.Value | The condition to test, read with Get. |
whenTrue | Any or Sprites.Reactive.Value | The value chosen while the condition is true. |
whenFalse | Any or Sprites.Reactive.Value | The value chosen while the condition is false. |
Returns a read-only Sprites.Reactive.Value holding whenTrue or whenFalse as the condition changes.
const on = Sprites.Reactive.Value(true);
const label = Sprites.Logic.Select(on, 'Yes', 'No');
Sprites.Ui.Input.Checkbox(on);
Sprites.Ui.Dom.Text(' label = ', label);