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
fb1984a9
authored
2012-08-10 02:36:41 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'model-as-context-on-function-calls'
2 parents
44468934
1594f8c0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
6 deletions
spec/rivets/binding.js
src/rivets.coffee
spec/rivets/binding.js
View file @
fb1984a
...
...
@@ -85,6 +85,13 @@ describe('Rivets.Binding', function() {
expect
(
binding
.
routine
).
toHaveBeenCalledWith
(
el
,
'awesome sweater'
);
});
it
(
'calls methods with the object as context'
,
function
()
{
binding
.
model
=
{
foo
:
'bar'
};
spyOn
(
binding
,
'routine'
);
binding
.
set
(
function
()
{
return
this
.
foo
;
});
expect
(
binding
.
routine
).
toHaveBeenCalledWith
(
el
,
binding
.
model
.
foo
);
});
describe
(
'on an event binding'
,
function
()
{
beforeEach
(
function
()
{
binding
.
options
.
special
=
'event'
;
...
...
@@ -110,19 +117,19 @@ describe('Rivets.Binding', function() {
});
});
});
describe
(
'publish()'
,
function
()
{
it
(
"should publish the value of a number input"
,
function
()
{
numberInput
=
document
.
createElement
(
'input'
);
numberInput
.
setAttribute
(
'type'
,
'number'
);
numberInput
.
setAttribute
(
'data-value'
,
'obj.num'
);
view
=
rivets
.
bind
(
numberInput
,
{
obj
:
{
num
:
42
}});
binding
=
view
.
bindings
[
0
];
model
=
binding
.
model
;
numberInput
.
value
=
42
;
spyOn
(
rivets
.
config
.
adapter
,
'publish'
);
binding
.
publish
({
target
:
numberInput
});
expect
(
rivets
.
config
.
adapter
.
publish
).
toHaveBeenCalledWith
(
model
,
'num'
,
'42'
);
...
...
@@ -135,7 +142,7 @@ describe('Rivets.Binding', function() {
binding
.
formatters
.
push
(
'awesome'
);
expect
(
binding
.
formattedValue
(
'hat'
)).
toBe
(
'awesome hat'
);
});
it
(
'uses formatters on the model'
,
function
()
{
model
.
modelAwesome
=
function
(
value
)
{
return
'model awesome '
+
value
};
binding
.
formatters
.
push
(
'modelAwesome'
);
...
...
@@ -149,7 +156,7 @@ describe('Rivets.Binding', function() {
};
binding
.
formatters
.
push
(
'awesome super'
);
});
it
(
'applies the formatter with arguments'
,
function
()
{
expect
(
binding
.
formattedValue
(
'jacket'
)).
toBe
(
'super awesome jacket'
);
});
...
...
src/rivets.coffee
View file @
fb1984a
...
...
@@ -48,7 +48,7 @@ class Rivets.Binding
@
routine
@
el
,
value
,
@
currentListener
@
currentListener
=
value
else
value
=
value
(
)
if
value
instanceof
Function
value
=
value
.
call
(
@
model
)
if
value
instanceof
Function
@
routine
@
el
,
value
# Subscribes to the model for changes at the specified keypath. Bi-directional
...
...
Please
register
or
sign in
to post a comment