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
89b89668
authored
2013-05-20 14:04:39 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Rewrite the each-* binder with some of the optimizations that @terrancesnyder ha…
…s implemented. [#157]
1 parent
f8d23781
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
29 deletions
src/rivets.coffee
src/rivets.coffee
View file @
89b8966
...
...
@@ -368,46 +368,47 @@ Rivets.binders =
"each-*"
:
block
:
true
bind
:
(
el
,
collection
)
->
el
.
removeAttribute
[
'data'
,
@
view
.
config
.
prefix
,
@
type
].
join
(
'-'
).
replace
'--'
,
'-'
unbind
:
(
el
,
collection
)
->
bind
:
(
el
)
->
attr
=
[
'data'
,
@
view
.
config
.
prefix
,
@
type
].
join
(
'-'
).
replace
'--'
,
'-'
@
marker
=
document
.
createComment
" rivets:
#{
@
type
}
"
@
iterated
=
[]
el
.
removeAttribute
attr
el
.
parentNode
.
insertBefore
@
marker
,
el
el
.
parentNode
.
removeChild
el
unbind
:
(
el
)
->
view
.
unbind
()
for
view
in
@
iterated
if
@
iterated
?
routine
:
(
el
,
collection
)
->
if
@
iterated
?
for
view
in
@
iterated
modelName
=
@
args
[
0
]
collection
=
collection
or
[]
if
@
iterated
.
length
>
collection
.
length
for
i
in
Array
@
iterated
.
length
-
collection
.
length
view
=
@
iterated
.
pop
()
view
.
unbind
()
e
.
parentNode
.
removeChild
e
for
e
in
view
.
els
else
@
marker
=
document
.
createComment
" rivets:
#{
@
type
}
"
el
.
parentNode
.
insertBefore
@
marker
,
el
el
.
parentNode
.
removeChild
el
@
marker
.
parentNode
.
removeChild
view
.
els
[
0
]
@
iterated
=
[]
for
model
,
index
in
collection
data
=
{}
data
[
modelName
]
=
model
if
collection
for
item
in
collection
data
=
{}
data
[
n
]
=
m
for
n
,
m
of
@
view
.
models
data
[
@
args
[
0
]]
=
item
itemEl
=
el
.
cloneNode
true
if
not
@
iterated
[
index
]
?
for
key
,
model
of
@
view
.
models
data
[
key
]
=
model
previous
=
if
@
iterated
.
length
@
iterated
[
@
iterated
.
length
-
1
].
els
[
0
]
else
@
marker
@
marker
.
parentNode
.
insertBefore
itemEl
,
previous
.
nextSibling
?
null
options
=
binders
:
@
view
.
options
.
binders
formatters
:
@
view
.
options
.
binders
config
:
{}
options
.
config
[
k
]
=
v
for
k
,
v
of
@
view
.
options
.
config
if
@
view
.
options
.
config
# Ensure preloadData is set to true since child elements won't get initiated otherwise until the next change (which might not be the first)
options
.
config
.
preloadData
=
true
view
=
new
Rivets
.
View
(
itemEl
,
data
,
options
)
view
.
bind
()
@
iterated
.
push
view
template
=
el
.
cloneNode
true
@
iterated
.
push
rivets
.
bind
template
,
data
@
marker
.
parentNode
.
insertBefore
template
,
previous
.
nextSibling
else
if
@
iterated
[
index
].
models
[
modelName
]
isnt
model
@
iterated
[
index
].
update
data
"class-*"
:
(
el
,
value
)
->
elClass
=
"
#{
el
.
className
}
"
...
...
Please
register
or
sign in
to post a comment