View Source Reactive.Ref (Reactive State v0.1.0)

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

Retrieve the state of a reactive process, and register the current process as dependent of that process, with the call ID of the current process. You should use the Reactive.reactive macro to manage reactive relationships instead

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> ref = Ref.new(0)
iex> Ref.get(ref)
0

Retrieve the state of a reactive process, and register the current process as dependent of that process, with the call ID of the current process. You should use the Reactive.reactive macro to manage reactive relationships instead

Example

iex> ref = Ref.new(0)
iex> Ref.get(ref)
0

Create a reactive process

Example

iex> ref = Ref.new(0)
iex> Ref.get(ref)
0

Set the state for a reactive process

Example

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> ref = Ref.new(0)
iex> Ref.set_fn(ref, fn state -> state + 1 end)
:ok
iex> Ref.get(ref)
1