Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
rivets
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
28fbf16b
authored
2013-11-01 00:12:05 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Set the KeypathObserver on the Rivets object. Add missing source documentation.
1 parent
cd102889
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
3 deletions
src/bindings.coffee
src/keypath_observer.coffee
src/bindings.coffee
View file @
28fbf16
...
...
@@ -12,6 +12,7 @@ class Rivets.Binding
@
setBinder
()
@
setObserver
()
# Sets the binder to use when binding and syncing.
setBinder
:
=>
unless
@
binder
=
@
view
.
binders
[
@
type
]
for
identifier
,
value
of
@
view
.
binders
...
...
@@ -25,8 +26,10 @@ class Rivets.Binding
@
binder
or=
@
view
.
binders
[
'*'
]
@
binder
=
{
routine
:
@
binder
}
if
@
binder
instanceof
Function
# Sets a keypath observer that will notify this binding when any intermediary
# keys are changed.
setObserver
:
=>
@
observer
=
new
KeypathObserver
@
view
,
@
view
.
models
,
@
keypath
,
(
obs
)
=>
@
observer
=
new
Rivets
.
KeypathObserver
@
view
,
@
view
.
models
,
@
keypath
,
(
obs
)
=>
@
unbind
true
if
@
key
@
model
=
obs
.
target
@
bind
true
if
@
key
...
...
@@ -95,7 +98,7 @@ class Rivets.Binding
if
@
options
.
dependencies
?
.
length
for
dependency
in
@
options
.
dependencies
observer
=
new
KeypathObserver
@
view
,
@
model
,
dependency
,
(
obs
,
prev
)
=>
observer
=
new
Rivets
.
KeypathObserver
@
view
,
@
model
,
dependency
,
(
obs
,
prev
)
=>
key
=
obs
.
key
@
view
.
adapters
[
key
.
interface
].
unsubscribe
prev
,
key
.
path
,
@
sync
@
view
.
adapters
[
key
.
interface
].
subscribe
obs
.
target
,
key
.
path
,
@
sync
...
...
src/keypath_observer.coffee
View file @
28fbf16
class
KeypathObserver
# Rivets.KeypathObserver
# ----------------------
# Parses and observes a full keypath with the appropriate adapters. Also
# intelligently re-realizes the keypath when intermediary keys change.
class
Rivets
.
KeypathObserver
# Performs the initial parse, variable instantiation and keypath realization.
constructor
:
(
@
view
,
@
model
,
@
keypath
,
@
callback
)
->
@
parse
()
@
objectPath
=
[]
@
target
=
@
realize
()
# Parses the keypath using the interfaces defined on the view. Sets variables
# for the tokenized keypath, as well as the end key.
parse
:
=>
interfaces
=
(
k
for
k
,
v
of
@
view
.
adapters
)
...
...
@@ -17,12 +25,15 @@ class KeypathObserver
@
tokens
=
Rivets
.
KeypathParser
.
parse
path
,
interfaces
,
root
@
key
=
@
tokens
.
pop
()
# Updates the keypath. This is called when any intermediate key is changed.
update
:
=>
unless
(
next
=
@
realize
())
is
@
target
prev
=
@
target
@
target
=
next
@
callback
@
,
prev
# Realizes the full keypath, attaching observers for every key and correcting
# old observers to any changed objects in the keypath.
realize
:
=>
current
=
@
model
...
...
@@ -40,6 +51,7 @@ class KeypathObserver
current
# Unobserves any current observers set up on the keys.
unobserve
:
=>
for
token
,
index
in
@
tokens
if
obj
=
@
objectPath
[
index
]
...
...
Please
register
or
sign in
to post a comment