novdom/state
Types
Attention: Will be opaque soon.
pub type State(a) {
State(state_id: StateId)
StateList(state_id: StateId)
StateItem(state_id: StateId, root_id: StateId)
}
Constructors
-
State(state_id: StateId)
-
StateList(state_id: StateId)
-
StateItem(state_id: StateId, root_id: StateId)
Functions
pub fn create(init: a) -> State(a)
Create a state with an initial value.
If you want to create a state with a list, use create_list(..)
- it is way more efficient plus you can use all novdom/state/list
functions.
pub fn create_list(init: List(a)) -> State(List(a))
Create a state with a list as an initial value.
This enables all novdom/state/list
functions.
pub fn create_list_with_id(
id: String,
init: List(a),
) -> State(List(a))
Create a state with a list as an initial value and a specific id.
For more information, see create_with_id(..)
and create_list(..)
.
pub fn create_with_id(id: String, init: a) -> State(a)
Create a state with a specific id.
If a state with the same id already exists, it will be overwritten.
To get a state with a specific id, use from_id(..)
.
pub fn from_id(id: String) -> State(a)
Get a state with a specific id.
Warning: The state with this id needs to be created before (see create_with_id(..)
). Otherwise this can lead to unexpected behavior.
pub fn list_from_id(id: String) -> State(List(a))
Get a state with a specific id that holds a list value.
For more information, see from_id(..)
.
pub fn listen(state: State(a), callback: fn(a) -> Nil) -> Nil
Listen to a state.
The callback will be called whenever the state changes.
pub fn update(state: State(a), new: a) -> Nil
Update / overwrite the value of a state.
If you want to update a StateList
, see novdom/state/list
.
pub fn update_fn(state: State(a), do: fn(a) -> a) -> a
Update / overwrite the value of a state using a function that receives the current value of the state.
If you want to update a StateList
, see novdom/state/list
.