OneOf, And & Or Utilities
Markup comes with additional utilities that work as operators and allows you to check a value from a bunch. This comes in form of and
, or
, and oneOf
utilities.
oneOf
The oneOf
works like the is and isNot utilities but instead of checking a one value, it checks many.
const [status, setStatus] = state('pending')
html`${when(
oneOf(status, ['pending', 'idle']),
html`<p>loading...</p>`,
html`<p>done</p>`
)}`
It takes the value/state you want to check and an array of values to check against. The utility simply checks the value exactly.
and
The and
utility works like the &&
(Logical AND). It will return true
only if all values are TRUTHY.
html`${when(
and(loadingTodos, noTodos),
html`<p>loading...</p>`,
html`<p>done</p>`
)}`
You can list any amount of values for the check:
and(value1, value2, ..., valueN)
or
The or
utility works like the ||
(Logical OR). It will return true
only if at least one of the values are TRUTHY.
html`${when(
or(loadingTodos, noTodos),
html`<p>loading...</p>`,
html`<p>done</p>`
)}`
You can list any amount of values for the check:
or(value1, value2, ..., valueN)