Skip to content

Commit

Permalink
Pull request/d1e3d0be (#143)
Browse files Browse the repository at this point in the history
* fixes #141

* small documentations fixes for the initial bind
  • Loading branch information
yakir12 authored and JobJob committed May 19, 2017
1 parent d93e8b2 commit 4303fde
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/operators.jl
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4303fde

Please sign in to comment.