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
a7963f51
authored
2012-11-08 19:32:20 -0800
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'issue-85'
2 parents
e0a4fdc8
6c26680c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
2 deletions
spec/rivets/binding.js
src/rivets.coffee
spec/rivets/binding.js
View file @
a7963f5
...
...
@@ -29,6 +29,17 @@ describe('Rivets.Binding', function() {
expect
(
rivets
.
config
.
adapter
.
subscribe
).
toHaveBeenCalledWith
(
model
,
'name'
,
binding
.
sync
);
});
it
(
"calls the binder's bind method if one exists"
,
function
()
{
expect
(
function
(){
binding
.
bind
();
}).
not
.
toThrow
(
new
Error
());
binding
.
binder
.
bind
=
function
(){};
spyOn
(
binding
.
binder
,
'bind'
);
binding
.
bind
();
expect
(
binding
.
binder
.
bind
).
toHaveBeenCalled
();
});
describe
(
'with preloadData set to true'
,
function
()
{
beforeEach
(
function
()
{
rivets
.
config
.
preloadData
=
true
;
...
...
@@ -54,6 +65,17 @@ describe('Rivets.Binding', function() {
binding
.
bind
();
expect
(
binding
.
set
).
toHaveBeenCalledWith
(
'espresso'
);
});
it
(
"calls the binder's bind method if one exists"
,
function
()
{
expect
(
function
(){
binding
.
bind
();
}).
not
.
toThrow
(
new
Error
());
binding
.
binder
.
bind
=
function
(){};
spyOn
(
binding
.
binder
,
'bind'
);
binding
.
bind
();
expect
(
binding
.
binder
.
bind
).
toHaveBeenCalled
();
});
});
describe
(
'with dependencies'
,
function
()
{
...
...
@@ -70,6 +92,36 @@ describe('Rivets.Binding', function() {
});
});
describe
(
'unbind()'
,
function
()
{
it
(
"calls the binder's unbind method if one exists"
,
function
()
{
expect
(
function
(){
binding
.
unbind
();
}).
not
.
toThrow
(
new
Error
());
binding
.
binder
.
unbind
=
function
(){};
spyOn
(
binding
.
binder
,
'unbind'
);
binding
.
unbind
();
expect
(
binding
.
binder
.
unbind
).
toHaveBeenCalled
();
});
describe
(
'with the bypass option set to true'
,
function
()
{
beforeEach
(
function
()
{
binding
.
options
.
bypass
=
true
;
});
it
(
"calls the binder's unbind method if one exists"
,
function
()
{
expect
(
function
(){
binding
.
unbind
();
}).
not
.
toThrow
(
new
Error
());
binding
.
binder
.
unbind
=
function
(){};
spyOn
(
binding
.
binder
,
'unbind'
);
binding
.
unbind
();
expect
(
binding
.
binder
.
unbind
).
toHaveBeenCalled
();
});
});
});
describe
(
'set()'
,
function
()
{
it
(
'performs the binding routine with the supplied value'
,
function
()
{
spyOn
(
binding
.
binder
,
'routine'
);
...
...
src/rivets.coffee
View file @
a7963f5
...
...
@@ -69,10 +69,11 @@ class Rivets.Binding
# routines will also listen for changes on the element to propagate them back
# to the model.
bind
:
=>
@
binder
.
bind
?
.
call
@
,
@
el
if
@
options
.
bypass
@
sync
()
else
@
binder
.
bind
?
.
call
@
,
@
el
Rivets
.
config
.
adapter
.
subscribe
@
model
,
@
keypath
,
@
sync
@
sync
()
if
Rivets
.
config
.
preloadData
...
...
@@ -90,8 +91,9 @@ class Rivets.Binding
# Unsubscribes from the model and the element.
unbind
:
=>
@
binder
.
unbind
?
.
call
@
,
@
el
unless
@
options
.
bypass
@
binder
.
unbind
?
.
call
@
,
@
el
Rivets
.
config
.
adapter
.
unsubscribe
@
model
,
@
keypath
,
@
sync
if
@
options
.
dependencies
?
.
length
...
...
Please
register
or
sign in
to post a comment