View Source Reactive.Ref (Reactive State v0.2.3)
Wrapper to work with reactive state directly
Example
iex> use Reactive
iex> ref = Ref.new(0) #PID<0.204.0>
iex> Ref.get(ref)
0
iex> Ref.set(ref, 1)
:ok
iex> Ref.get(ref)
1
Summary
Functions
Retrieve the state of a reactive process
Create a reactive process
Set the state for a reactive process
Set the state for a reactive process through a function that receives the old value
Functions
Retrieve the state of a reactive process
Example
iex> use Reactive
iex> ref = Ref.new(0)
iex> Ref.get(ref)
0
Create a reactive process
Example
iex> use Reactive
iex> ref = Ref.new(0)
iex> Ref.get(ref)
0
Set the state for a reactive process
Example
iex> use Reactive
iex> ref = Ref.new(0)
iex> Ref.set(ref, 1)
:ok
iex> Ref.get(ref)
1
Set the state for a reactive process through a function that receives the old value
Example
iex> use Reactive
iex> Reactive.Supervisor.ensure_started()
iex> ref = Ref.new(0)
iex> Ref.set_fn(ref, fn state -> state + 1 end)
:ok
iex> Ref.get(ref)
1