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
19d6db6b
authored
2012-11-17 11:26:34 -0800
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge pull request #98 from mikeric/allow-publishing-falsey-values
Allow publishing falsey values
2 parents
924b7ba1
51018f8d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
19 deletions
src/rivets.coffee
src/rivets.coffee
View file @
19d6db6
...
...
@@ -37,17 +37,17 @@ class Rivets.Binding
for
formatter
in
@
formatters
args
=
formatter
.
split
/\s+/
id
=
args
.
shift
()
value
=
if
@
model
[
id
]
instanceof
Function
@
model
[
id
]
value
,
args
...
else
if
Rivets
.
formatters
[
id
]
if
Rivets
.
formatters
[
id
].
read
instanceof
Function
Rivets
.
formatters
[
id
].
read
value
,
args
...
else
if
Rivets
.
formatters
[
id
]
instanceof
Function
# could occur if fmt = { publish: function() {}}
Rivets
.
formatters
[
id
]
value
,
args
...
else
# skip if no read function exists
value
else
# skip if no formatter exists
value
formatter
=
if
@
model
[
id
]
instanceof
Function
@
model
[
id
]
else
Rivets
.
formatters
[
id
]
if
formatter
?
.
read
instanceof
Function
value
=
formatter
.
read
value
,
args
...
else
if
formatter
instanceof
Function
value
=
formatter
value
,
args
...
value
# Sets the value for the binding. This Basically just runs the binding routine
...
...
@@ -70,17 +70,14 @@ class Rivets.Binding
# Publishes the value currently set on the input element back to the model.
publish
:
=>
value
=
getInputValue
@
el
if
@
formatters
i
=
@
formatters
.
length
-
1
while
(
i
>
-
1
)
formatter
=
@
formatters
[
i
]
for
formatter
in
@
formatters
.
slice
(
0
).
reverse
()
args
=
formatter
.
split
/\s+/
id
=
args
.
shift
()
# only re-assign if there is a two-way formatter.
if
Rivets
.
formatters
[
id
]
and
Rivets
.
formatters
[
id
]
.
publish
if
Rivets
.
formatters
[
id
]
?
.
publish
value
=
Rivets
.
formatters
[
id
].
publish
value
,
args
...
i
--
if
(
value
)
Rivets
.
config
.
adapter
.
publish
@
model
,
@
keypath
,
value
# Subscribes to the model for changes at the specified keypath. Bi-directional
...
...
Please
register
or
sign in
to post a comment