From 4303fdecb001095b0515d44e8e303edca8dbc133 Mon Sep 17 00:00:00 2001 From: Yakir Luc Gagnon <12.yakir@gmail.com> Date: Fri, 19 May 2017 16:50:02 +0200 Subject: [PATCH] Pull request/d1e3d0be (#143) * fixes #141 * small documentations fixes for the initial bind --- src/operators.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/operators.jl b/src/operators.jl index f5e921e..08df547 100644 --- a/src/operators.jl +++ b/src/operators.jl @@ -308,12 +308,14 @@ const _bindings = Dict() # XXX GC Issue? can't use WeakKeyDict with Pairs... const _active_binds = Dict() """ - `bind!(dest, src, twoway=true)` + `bind!(dest, src, twoway=true; initial=true)` for every update to `src` also update `dest` with the same value and, if -`twoway` is true, vice-versa. +`twoway` is true, vice-versa. If `initial` is false, `dest` will only be updated +to `src`'s value when `src` next updates, otherwise (if `initial` is true) both +`dest` and `src` will take `src`'s value immediately. """ -function bind!(dest::Signal, src::Signal, twoway=true) +function bind!(dest::Signal, src::Signal, twoway=true; initial=true) if haskey(_bindings, src=>dest) # subsequent bind!(dest, src) after initial should be a no-op # though we should allow a change in preference for twoway bind. @@ -359,7 +361,7 @@ function bind!(dest::Signal, src::Signal, twoway=true) finalizer(src, (src)->unbind!(dest, src, twoway)) _bindings[src=>dest] = map(bind_updater, src; name="binder: $(src.name)=>$(dest.name)") - bind_updater(src.value) # init now that _bindings[src=>dest] is set + initial && bind_updater(src.value) # init now that _bindings[src=>dest] is set if twoway bind!(src, dest, false)