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.
text = Signal("")
text2 = map(s -> "Bye $s", text)
subscribe!(text) do s
println("Hello $s")
end
push!(text, "world")
value(text)
value(text2)ReactiveBasics.bind! — Function.bind!(a, b)
bind!(a, b, twoway)
For every update to b also update a with the same value and, if twoway is true, vice-versa. Initially update a with the value in b.
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)
Transform the Signal into another Signal using a function. It's like map, but it's meant for functions that return Signals.
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)
Zips given signals first and then applies the map function onto the zipped value. This omits the double calculation when using map.
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; ntasks, batch_size)
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.
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)
Transform the Signal into another Signal using a function.
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.