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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
15 deletions
src/rivets.coffee
src/rivets.coffee
View file @
f1a9565
...
...
@@ -9,6 +9,22 @@ Rivets = {}
# Polyfill For String::trim.
unless
String
::
trim
then
String
::
trim
=
->
@
replace
/^\s+|\s+$/g
,
''
findBinder
=
(
type
)
->
unless
binder
=
Rivets
.
binders
[
type
]
binder
=
Rivets
.
binders
[
'*'
]
for
identifier
,
value
of
Rivets
.
binders
if
identifier
isnt
'*'
and
identifier
.
indexOf
(
'*'
)
isnt
-
1
regexp
=
new
RegExp
"^
#{
identifier
.
replace
(
'*'
,
'(.+)'
)
}
$"
if
regexp
.
test
type
binder
=
value
args
=
regexp
.
exec
type
args
.
shift
()
if
binder
instanceof
Function
binder
=
{
routine
:
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
...
...
@@ -16,21 +32,8 @@ class Rivets.Binding
# to listen for changes.
constructor
:
(
@
el
,
@
type
,
@
model
,
@
keypath
,
options
)
->
@
options
=
(
options
||=
{})
unless
binder
=
Rivets
.
binders
[
type
]
binder
=
Rivets
.
binders
[
'*'
]
for
identifier
,
value
of
Rivets
.
binders
if
identifier
isnt
'*'
and
identifier
.
indexOf
(
'*'
)
isnt
-
1
regexp
=
new
RegExp
"^
#{
identifier
.
replace
(
'*'
,
'(.+)'
)
}
$"
if
regexp
.
test
type
binder
=
value
args
=
regexp
.
exec
type
args
.
shift
()
@
args
=
args
if
binder
instanceof
Function
binder
=
{
routine
:
binder
}
@
binder
=
binder
[
@
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