Is & IsNot Helpers

This library is function-oriented but things can get messy when you try to perform multiple logic directly in the template. However, that is not the reason the most of the helpers exist.

All helpers are used to perform side effects, meaning, to react to state changes. Instead of using the effect helper for everything, you can use ones with specific capabilities that are more readable and easier to use.

is helper

The is helper will return a boolean whether it is equal.

It takes two arguments and both are required.

is(VALUE_OR_STATE, CHECKER_OR_VALUE)

  • VALUE_OR_STATE: It can be any value or a StateGetter for any value.
  • CHECKER_OR_VALUE: A static value to check against, or a function that does the checking and return true or false.
html`${is(val, isNumber)}`

It can be used anywhere in the template, inside templates, as attribute values and even body content.

html`<button disabled="${is(status, 'logged')}">login</button>`

You can also nest helpers to compose more complex render logic.

html`${when(is(status, 'logged'), "Logged", "Not Logged")}`

isNot helper

The isNot helper works the same as the is helper but checks the opposite.

html`${isNot(val, n => n typeof "number")}`