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
25c5bf2f
authored
2013-09-06 17:29:23 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Implement smarter nested dependency paths, originating from the target object.
1 parent
87f02d3e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
19 deletions
src/bindings.coffee
src/bindings.coffee
View file @
25c5bf2
...
...
@@ -9,6 +9,7 @@ class Rivets.Binding
constructor
:
(
@
view
,
@
el
,
@
type
,
@
keypath
,
@
options
=
{})
->
@
formatters
=
@
options
.
formatters
||
[]
@
objectPath
=
[]
@
dependencies
=
[]
@
setBinder
()
@
setModel
()
...
...
@@ -116,32 +117,31 @@ class Rivets.Binding
if
@
options
.
dependencies
?
.
length
for
dependency
in
@
options
.
dependencies
if
/^\./
.
test
dependency
model
=
@
model
keypath
=
dependency
.
substr
1
else
dependency
=
dependency
.
split
'.'
model
=
@
view
.
models
[
dependency
.
shift
()]
keypath
=
dependency
.
join
'.'
interfaces
=
(
k
for
k
,
v
of
@
view
.
adapters
)
prefix
=
dependency
[
0
]
in
interfaces
root
=
if
prefix
then
dependency
[
0
]
else
'.'
path
=
if
prefix
then
dependency
.
substr
(
1
)
else
dependency
tokens
=
Rivets
.
KeypathParser
.
parse
path
,
interfaces
,
root
key
=
tokens
.
pop
()
@
view
.
adapters
[
'.'
].
subscribe
model
,
keypath
,
@
sync
model
=
@
model
for
token
in
tokens
model
=
@
view
.
adapters
[
token
.
interface
].
read
model
,
token
.
path
@
view
.
adapters
[
key
.
interface
].
subscribe
model
,
key
.
path
,
@
sync
@
dependencies
.
push
[
model
,
key
]
# Unsubscribes from the model and the element.
unbind
:
=>
@
binder
.
unbind
?
.
call
@
,
@
el
@
view
.
adapters
[
@
key
.
interface
].
unsubscribe
@
model
,
@
key
.
path
,
@
sync
if
@
options
.
dependencies
?
.
length
for
dependency
in
@
options
.
dependencies
if
/^\./
.
test
dependency
model
=
@
model
keypath
=
dependency
.
substr
1
else
dependency
=
dependency
.
split
'.'
model
=
@
view
.
models
[
dependency
.
shift
()]
keypath
=
dependency
.
join
'.'
@
view
.
adapters
[
'.'
].
unsubscribe
model
,
keypath
,
@
sync
if
@
dependencies
.
length
for
dep
in
@
dependencies
@
view
.
adapters
[
dep
[
1
].
interface
].
unsubscribe
dep
[
0
],
dep
[
1
].
path
,
@
sync
@
dependencies
=
[]
# Updates the binding's model from what is currently set on the view. Unbinds
# the old model first and then re-binds with the new model.
...
...
Please
register
or
sign in
to post a comment