ReactiveBasics API
ReactiveBasics.SignalBase.Iterators.zipBase.asyncmapBase.filterBase.mapBase.mergeBase.push!ReactiveBasics.bind!ReactiveBasics.droprepeatsReactiveBasics.filterwhenReactiveBasics.flatmapReactiveBasics.flattenReactiveBasics.foldpReactiveBasics.preserveReactiveBasics.previousReactiveBasics.sampleonReactiveBasics.subscribe!ReactiveBasics.unsubscribe!ReactiveBasics.valueReactiveBasics.zipmap
ReactiveBasics.Signal — Type.A Signal is value that will contain a value in the future. The value of the Signal can change at any time.
Use map to derive new Signals, subscribe! to subscribe to updates of a Signal, and push! to update the current value of a Signal. value returns the current value of a Signal. The type of the Signal can optionally be set by the first parameter. Otherwise it will default to the type of the initial value.
text = Signal("")
text2 = map(s -> "Bye $s", text)
subscribe!(text) do s
println("Hello $s")
end
push!(text, "world")
value(text)
value(text2)
float_number = Signal(Float64, 1) # Optionally set the type of the SignalReactiveBasics.bind! — Function.bind!(a, b)
bind!(a, b, twoway; initial)
For every update to b also update a with the same value and, if twoway is true, ice-versa. If initial is set to true, a is updated immediately and, if twoway is true, b is updated immediately as well.
ReactiveBasics.droprepeats — Method.droprepeats(input)
Drop updates to input whenever the new value is the same as the previous value of the Signal.
ReactiveBasics.filterwhen — Method.filterwhen(predicate, default, u)
Keep updates to u only when predicate is true. If predicate is false initially, the specified default value is used.
ReactiveBasics.flatmap — Method.flatmap(f, input; init, typ)
Transform the Signal into another Signal using a function. It's like map, but it's meant for functions that return Signals. The initial value of the output Signal can optionally be set via init. Otherwise it defaults to f(input.value).value, where f is the passed function and input is the passed Signal of Signals. The type of the output Signal can optionally be set via typ. Otherwise it defaults to the type of the initial value.
ReactiveBasics.flatten — Method.flatten(input)
Flatten a Signal of Signals into a Signal which holds the value of the current Signal.
ReactiveBasics.foldp — Method.foldp(f, v0, us)
Fold/map over past values. The first argument to the function f is an accumulated value that the function can operate over, and the second is the current value coming in. v0 is the initial value of the accumulated value.
a = Signal(2)
# accumulate sums coming in from a, starting at zero
b = foldp(+, 0, a) # b == 2
push!(a, 2) # b == 4
push!(a, 3) # b == 7ReactiveBasics.preserve — Method.preserve(x)
For compatibility with Reactive. It just returns the original Signal because this isn't needed with direct push! updates.
ReactiveBasics.previous — Function.previous(input)
previous(input, default)
Create a Signal which holds the previous value of input. You can optionally specify a different initial value.
ReactiveBasics.sampleon — Method.sampleon(a, b)
Sample the value of b whenever a updates.
ReactiveBasics.subscribe! — Method.subscribe!(f, u)
Subscribe to the changes of this Signal. Every time the Signal is updated, the function f runs.
ReactiveBasics.unsubscribe! — Method.unsubscribe!(f, u)
Unsubscribe to the changes of this Signal.
ReactiveBasics.value — Method.value(u)
The current value of the Signal u.
ReactiveBasics.zipmap — Method.zipmap(f, u, us; init, typ)
Zips given signals first and then applies the map function onto the zipped value. This omits the double calculation when using map. The initial value of the output Signal can optionally be set via init. Otherwise it defaults to f(zip(u, us...).value...), where f is the passed function and (u, us...) are the passed Signals. The type of the output Signal can optionally be set via typ. Otherwise it defaults to the type of the initial value.
as = Signal(1)
bs = map(a -> a * 0.1, as)
cs = zipmap((a,b) -> a + b, as, bs) # This calculation is done once for
# every change in `as`Base.Iterators.zip — Method.zip(u, us)
Zip (combine) Signals into the current Signal. The value of the Signal is a Tuple of the values of the contained Signals.
signal = zip(Signal("Hello"), Signal("World"))
value(signal) # ("Hello", "World")Base.asyncmap — Method.asyncmap(f, init, input, inputs; typ)
An asynchronous version of map that returns a Signal that is updated after f operates asynchronously. The initial value of the returned Signal (the init arg) must be supplied. The type of the output Signal can optionally be set via typ. Otherwise it defaults to the type of the initial value.
Base.filter — Method.Return a Signal that updates based on the Signal u if f(value(u)) evaluates to true.
Base.map — Method.map(f, u; init, typ)
Transform the Signal into another Signal using a function. The initial value of the output Signal can optionally be set via init. Otherwise it defaults to f(u.value), where f is the passed function and u is the passed Signal. The type of the output Signal can optionally be set via typ. Otherwise it defaults to the type of the initial value.
Base.merge — Method.merge(u, us)
Merge Signals into the current Signal. The value of the Signal is that from the most recent update.
Base.push! — Method.push!(u, val)
Update the value of a Signal and propagate the change.