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
6e927599
authored
2012-07-05 15:58:06 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Make sure that purposely "falsey" values can be set for a binding.
1 parent
aea72d47
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
11 deletions
lib/rivets.js
src/rivets.coffee
lib/rivets.js
View file @
6e92759
...
...
@@ -23,28 +23,23 @@
Binding
.
prototype
.
set
=
function
(
value
)
{
var
formatter
,
_i
,
_len
,
_ref
;
if
(
value
==
null
)
{
value
=
null
;
}
if
(
value
||
(
value
=
Rivets
.
config
.
adapter
.
read
(
this
.
context
,
this
.
keypath
)))
{
_ref
=
this
.
formatters
;
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
formatter
=
_ref
[
_i
];
value
=
Rivets
.
config
.
formatters
[
formatter
](
value
);
}
return
this
.
routine
(
this
.
el
,
value
);
}
};
Binding
.
prototype
.
bind
=
function
()
{
var
_ref
,
_this
=
this
;
if
(
Rivets
.
config
.
preloadData
)
{
this
.
set
();
}
Rivets
.
config
.
adapter
.
subscribe
(
this
.
context
,
this
.
keypath
,
function
(
value
)
{
return
_this
.
set
(
value
);
});
if
(
Rivets
.
config
.
preloadData
)
{
this
.
set
(
Rivets
.
config
.
adapter
.
read
(
this
.
context
,
this
.
keypath
));
}
if
(
_ref
=
this
.
type
,
__indexOf
.
call
(
bidirectionals
,
_ref
)
>=
0
)
{
return
this
.
el
.
addEventListener
(
'change'
,
function
(
e
)
{
var
el
;
...
...
src/rivets.coffee
View file @
6e92759
...
...
@@ -16,8 +16,7 @@ class Rivets.Binding
# Sets a value for this binding. Basically just runs the routine on the
# element with a suplied value and applies any formatters.
set
:
(
value
=
null
)
=>
if
value
or=
Rivets
.
config
.
adapter
.
read
@
context
,
@
keypath
set
:
(
value
)
=>
for
formatter
in
@
formatters
value
=
Rivets
.
config
.
formatters
[
formatter
]
value
...
...
@@ -27,9 +26,11 @@ class Rivets.Binding
# Conditionally also does the inverse and listens to the element for changes
# to propogate back to the context object.
bind
:
=>
@
set
()
if
Rivets
.
config
.
preloadData
Rivets
.
config
.
adapter
.
subscribe
@
context
,
@
keypath
,
(
value
)
=>
@
set
value
if
Rivets
.
config
.
preloadData
@
set
Rivets
.
config
.
adapter
.
read
@
context
,
@
keypath
if
@
type
in
bidirectionals
@
el
.
addEventListener
'change'
,
(
e
)
=>
el
=
e
.
target
or
e
.
srcElement
...
...
Please
register
or
sign in
to post a comment