store
An immutable store structure, with the ability to add subscribers. Subscribe with callbacks that will be called when a set or update is called on a store. Checkout the mutable version, mut_cell with a mutable store that changes the value in place.
Install
gleam add store@1
import store
import gleam/int
import gleam/io
pub fn main() {
let cell = store.make(10)
let #(cell, unsub) =
cell
|> store.subscribe(fn(value) {
{ "value: " <> value |> int.to_string } |> io.println
})
let cell = cell |> store.set(20)
let cell = unsub(cell)
let cell = cell |> store.set(30)
cell
|> store.get
|> int.to_string
|> io.println
}
Further documentation can be found at https://hexdocs.pm/store.