14b3c772 by Michael Richards

Merge pull request #111 from terrancesnyder/Issue#110

Pull request for #110
2 parents 835f5406 36de3dba
......@@ -116,6 +116,12 @@ describe('Functional', function() {
expect(el.getElementsByTagName('li').length).toBe(2);
});
it('should not fail if the collection being bound to is null', function() {
data.set({ items: null});
rivets.bind(el, bindData);
expect(el.getElementsByTagName('li').length).toBe(0);
});
it('should re-loop over the collection and create new instances when the array changes', function() {
rivets.bind(el, bindData);
expect(el.getElementsByTagName('li').length).toBe(2);
......@@ -162,6 +168,7 @@ describe('Functional', function() {
expect(el.getElementsByTagName('li')[2]).toHaveTheTextContent('b');
expect(el.getElementsByTagName('li')[3]).toHaveTheTextContent('last');
})
});
});
......
......@@ -339,17 +339,18 @@ Rivets.binders =
@iterated = []
for item in collection
data = {}
data[n] = m for n, m of @view.models
data[@args[0]] = item
itemEl = el.cloneNode true
if @iterated.length > 0
previous = @iterated[@iterated.length - 1].els[0]
else
previous = @marker
@marker.parentNode.insertBefore itemEl, previous.nextSibling ? null
@iterated.push rivets.bind itemEl, data
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 @iterated.length > 0
previous = @iterated[@iterated.length - 1].els[0]
else
previous = @marker
@marker.parentNode.insertBefore itemEl, previous.nextSibling ? null
@iterated.push rivets.bind itemEl, data
"class-*": (el, value) ->
elClass = " #{el.className} "
......