novdom/state/list

Work with lists of items in a state (StateList).
(Created with create(..), novdom/state.create_list(..), novdom/state.create_list_with_id(..) or novdom/state.list_from_id(..))

Functions

pub fn create(init: List(a)) -> State(List(a))

Alias for novdom/state.create_list(..)

pub fn delete(item: State(a)) -> Nil

Delete this item from its list.

Attention: Only call this function if the item is a StateItem (derived from map(..) or get(..)).

pub fn get(
  from: State(List(a)),
  idx: Int,
) -> Result(State(a), Nil)

Get an item from a list. Returns an Error if the given index is out of bounds.

Attention: Only call this function if the given state is a StateList.

pub fn insert_after(item: State(a), new_item: State(a)) -> Nil

Insert a new item into the list after this item.

Attention: Only call this function if the item is a StateItem (derived from map(..) or get(..)).

pub fn insert_before(item: State(a), new_item: State(a)) -> Nil

Insert a new item into the list before this item.

Attention: Only call this function if the item is a StateItem (derived from map(..) or get(..)).

pub fn insert_value_after(item: State(a), value: a) -> Nil

Insert a new value into the list after this item.

Attention: Only call this function if the item is a StateItem (derived from map(..) or get(..)).

pub fn insert_value_before(item: State(a), value: a) -> Nil

Insert a new value into the list before this item.

Attention: Only call this function if the item is a StateItem (derived from map(..) or get(..)).

pub fn items(from: State(List(a))) -> List(State(a))

Get all items from a list.

Attention: Only call this function if the given state is a StateList.

pub fn map(
  parameter: List(Parameter),
  state_list: State(List(a)),
  do: fn(State(a)) -> Component,
) -> Component

Create a component that renders a list of items.
Whenever all items of a list need to be rendered, this function is way more efficient than using novdom/state/component.utilize(..).

The do function is called for each item in the list.
This will create a new state for each item, so you can listen to each item individually (e.g. by using novdom/state/component).
Each component created by the do function will be wrapped in a parent component.

Example:

use item <- state_list.map([], my_list)
div([tailwind("p-5 bg-blue-100")], [
    {
        use value <- state_component.utilize(item)
        text([], value)
    }
])

Attention: Only call this function if the given state is a StateList.

pub fn move_after(this: State(a), after: State(a)) -> Nil

Move this item after another item in the same list.

Attention: Only call this function if both items are StateItems (derived from map(..) or get(..)) and they are in the same list.

pub fn move_before(this: State(a), before: State(a)) -> Nil

Move this item before another item in the same list.

Attention: Only call this function if both items are StateItems (derived from map(..) or get(..)) and they are in the same list.

pub fn overwrite(state_: State(List(a)), new: List(a)) -> Nil

Alias for novdom/state.update(..)

pub fn replace(item: State(a), new_item: State(a)) -> Nil

Replace this item with a new item.

Attention: Only call this function if the item is a StateItem (derived from map(..) or get(..)).

pub fn replace_with_value(item: State(a), new: a) -> Nil

Replace this item with a new value.

Attention: Only call this function if the item is a StateItem (derived from map(..) or get(..)).

pub fn value(state_: State(List(a))) -> List(a)

Alias for novdom/state.value(..)

Search Document