Skip to content

Instantly share code, notes, and snippets.

@brett-shwom
Created June 6, 2014 21:34
Show Gist options
  • Save brett-shwom/3f861cf8530de19b6046 to your computer and use it in GitHub Desktop.
Save brett-shwom/3f861cf8530de19b6046 to your computer and use it in GitHub Desktop.
Array.shift() resulting in incorrect rerendering in Ractive.js
<script src='http://cdn.ractivejs.org/latest/ractive.js'></script>
<script type='text/template' id='template'>
<div class='attribute' data-a="{{#a}}{{.}}{{/a}}"></div> <!--shift is buggy here-->
<div class='innerHTML'> {{#a}}{{.}}{{/a}}</div> <!--shift() works fine here-->
<br/> Does the attribute equal the innerHTML : <span class='doesTheAttributeEqualTheInnerHTML'></span>
<br/> Actual Attribute : <span class='actualAttributeValue'></span>
<br/> Expected Attribute : <span class='expectedAttributeValue'></span>
</script>
<div id='container'></div>
<script>
data = {
a : [1,2,3]
}
ractive = new Ractive({
el : document.querySelector('#container'),
template : document.querySelector('#template').innerHTML,
data : data
})
setTimeout(function() {
data.a.shift() //here's the issue
setTimeout(function () {
ractive.find('.doesTheAttributeEqualTheInnerHTML').innerHTML = (ractive.find('.attribute').attributes.getNamedItem('data-a').value === ractive.find('.innerHTML').innerHTML);
ractive.find('.actualAttributeValue').innerHTML = ractive.find('.attribute').attributes.getNamedItem('data-a').value
ractive.find('.expectedAttributeValue').innerHTML = ractive.find('.innerHTML').innerHTML
})
},1000)
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment