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
f1a9565d
authored
2013-03-29 17:35:14 -0500
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Abstract out the binder lookup code from the Binding constructor.
1 parent
6ad92e53
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
9 deletions
src/rivets.coffee
src/rivets.coffee
View file @
f1a9565
...
...
@@ -9,13 +9,7 @@ Rivets = {}
# Polyfill For String::trim.
unless
String
::
trim
then
String
::
trim
=
->
@
replace
/^\s+|\s+$/g
,
''
# A single binding between a model attribute and a DOM element.
class
Rivets
.
Binding
# All information about the binding is passed into the constructor; the DOM
# element, the type of binding, the model object and the keypath at which
# to listen for changes.
constructor
:
(
@
el
,
@
type
,
@
model
,
@
keypath
,
options
)
->
@
options
=
(
options
||=
{})
findBinder
=
(
type
)
->
unless
binder
=
Rivets
.
binders
[
type
]
binder
=
Rivets
.
binders
[
'*'
]
for
identifier
,
value
of
Rivets
.
binders
...
...
@@ -25,12 +19,21 @@ class Rivets.Binding
binder
=
value
args
=
regexp
.
exec
type
args
.
shift
()
@
args
=
args
if
binder
instanceof
Function
binder
=
{
routine
:
binder
}
@
binder
=
binder
[
binder
,
args
]
# A single binding between a model attribute and a DOM element.
class
Rivets
.
Binding
# All information about the binding is passed into the constructor; the DOM
# element, the type of binding, the model object and the keypath at which
# to listen for changes.
constructor
:
(
@
el
,
@
type
,
@
model
,
@
keypath
,
options
)
->
@
options
=
(
options
||=
{})
[
@
binder
,
@
args
]
=
findBinder
(
type
)
@
formatters
=
options
.
formatters
||
[]
# Applies all the current formatters to the supplied value and returns the
...
...
Please
register
or
sign in
to post a comment