Current section
Files
Jump to
Current section
Files
lib/reactive_test.ex
defmodule Reactivity.Test do
require Integer
require Logger
alias Reactivity.Signal.Source
import Reactivity
def hot_cold(t) do
if t > 300 do
:"🌶️"
else
:"❄️"
end
end
def init do
{:ok, t} = Source.new(fn(_old_value) -> Enum.random(0..500) end, -1, 100, :temperature)
#{:ok, h} = Source.new(fn(_old_value) -> Enum.random(60..100) end, -1, 100, :humidity)
end
def test do
# Subscribe to new signals.
Reactivity.Registry.subscribe(self())
# Create a new signal :hotcold based on the source :temperature.
source(:temperature)
|> liftapp(&hot_cold/1)
|> register(:hotcold)
receive do
{:new_signal, source, name} ->
source(name)
|> liftapp(&(IO.puts "value for new signal #{name}: #{inspect &1}"))
end
# Create a new signal :kelvin based on the source :temperature
source(:temperature)
|> liftapp(&(&1 + 237.15))
|> register(:kelvin)
|> liftapp(&(IO.puts &1))
# Print out hot/cold for the kelvin signal
source(:kelvin)
|> liftapp(&hot_cold/1)
|> liftapp(&(Logger.debug "Kelvin: #{&1}"))
end
end