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
29f7ffa2
authored
2012-08-02 21:56:02 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge pull request #43 from mikeric/dependant-attributes-for-computed-properties
Computed properties
2 parents
c368733e
71bab2f6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
3 deletions
spec/rivets/binding.js
src/rivets.coffee
spec/rivets/binding.js
View file @
29f7ffa
...
...
@@ -26,7 +26,7 @@ describe('Rivets.Binding', function() {
it
(
'subscribes to the model for changes via the adapter'
,
function
()
{
spyOn
(
rivets
.
config
.
adapter
,
'subscribe'
);
binding
.
bind
();
expect
(
rivets
.
config
.
adapter
.
subscribe
).
toHaveBeenCalled
(
);
expect
(
rivets
.
config
.
adapter
.
subscribe
).
toHaveBeenCalled
With
(
model
,
'name'
,
binding
.
set
);
});
describe
(
'with preloadData set to true'
,
function
()
{
...
...
@@ -38,8 +38,8 @@ describe('Rivets.Binding', function() {
spyOn
(
binding
,
'set'
);
spyOn
(
rivets
.
config
.
adapter
,
'read'
);
binding
.
bind
();
expect
(
rivets
.
config
.
adapter
.
read
).
toHaveBeenCalledWith
(
model
,
'name'
);
expect
(
binding
.
set
).
toHaveBeenCalled
();
expect
(
rivets
.
config
.
adapter
.
read
).
toHaveBeenCalled
();
});
});
...
...
@@ -55,6 +55,19 @@ describe('Rivets.Binding', function() {
expect
(
binding
.
set
).
toHaveBeenCalledWith
(
'espresso'
);
});
});
describe
(
'with dependencies'
,
function
()
{
beforeEach
(
function
()
{
binding
.
options
.
dependencies
=
[
'fname'
,
'lname'
];
});
it
(
'sets up observers on the dependant attributes'
,
function
()
{
spyOn
(
rivets
.
config
.
adapter
,
'subscribe'
);
binding
.
bind
();
expect
(
rivets
.
config
.
adapter
.
subscribe
).
toHaveBeenCalledWith
(
model
,
'fname'
,
binding
.
dependencyCallbacks
[
'fname'
]);
expect
(
rivets
.
config
.
adapter
.
subscribe
).
toHaveBeenCalledWith
(
model
,
'lname'
,
binding
.
dependencyCallbacks
[
'lname'
]);
});
});
});
describe
(
'set()'
,
function
()
{
...
...
src/rivets.coffee
View file @
29f7ffa
...
...
@@ -63,6 +63,18 @@ class Rivets.Binding
if
Rivets
.
config
.
preloadData
@
set
Rivets
.
config
.
adapter
.
read
@
model
,
@
keypath
if
@
options
.
dependencies
?
.
length
@
dependencyCallbacks
=
{}
for
keypath
in
@
options
.
dependencies
callback
=
@
dependencyCallbacks
[
keypath
]
=
(
value
)
=>
@
set
if
@
options
.
bypass
@
model
[
@
keypath
]
else
Rivets
.
config
.
adapter
.
read
@
model
,
@
keypath
Rivets
.
config
.
adapter
.
subscribe
@
model
,
keypath
,
callback
if
@
type
in
@
bidirectionals
bindEvent
@
el
,
'change'
,
@
publish
...
...
@@ -75,6 +87,11 @@ class Rivets.Binding
unbind
:
=>
Rivets
.
config
.
adapter
.
unsubscribe
@
model
,
@
keypath
,
@
set
if
@
options
.
dependencies
?
.
length
for
keypath
in
@
options
.
dependencies
callback
=
@
dependencyCallbacks
[
keypath
]
Rivets
.
config
.
adapter
.
unsubscribe
@
model
,
keypath
,
callback
if
@
type
in
@
bidirectionals
@
el
.
removeEventListener
'change'
,
@
publish
...
...
@@ -104,12 +121,16 @@ class Rivets.View
type
=
attribute
.
name
.
replace
bindingRegExp
,
''
pipes
=
(
pipe
.
trim
()
for
pipe
in
attribute
.
value
.
split
'|'
)
path
=
pipes
.
shift
().
split
(
/(\.|:)/
)
context
=
(
ctx
.
trim
()
for
ctx
in
pipes
.
shift
().
split
'>'
)
path
=
context
.
shift
().
split
/(\.|:)/
options
.
formatters
=
pipes
model
=
@
models
[
path
.
shift
()]
options
.
bypass
=
path
.
shift
()
is
':'
keypath
=
path
.
join
()
if
dependencies
=
context
.
shift
()
options
.
dependencies
=
dependencies
.
split
/\s+/
if
eventRegExp
.
test
type
type
=
type
.
replace
eventRegExp
,
''
options
.
special
=
"event"
...
...
Please
register
or
sign in
to post a comment