Here is the problem (Ractive.js v0.7.3): http://jsfiddle.net/Inversion/hLym2xcy/
r = new Ractive
el: 'cont'
template: '''
{{#task.options}}
{{#if pros}}
inside if
{{#each filter(.pros)}}<li class='{{set_class(.)}}'>+{{.v}}</li>{{/each}}
{{/if}}
{{/task.options}}
'''
data:
task:
options: [{pros:[{v:1}]}]
set_class: (o)-> o.v
filter: (arr)-> console.log(arr);arr || []
setTimeout(
-> r.set('task.options.0.pros', undefined)
2000
)
On r.set
operation "inside if" is not printed out as expected, but #each
tries to work with an undefined array which is not expected.
I cannot guarantee presence of an pros
array and that's why I used {{#if pros}}
to do not use it, but seems like it doesn't work.
console.log(arr)
is added to see if filter is actually called, and it is.
Also when I try to return []
from the filter it still calls set_class
which is unexpected because there is nothing to iterate.
Is there a way to overcome these unexpected problems?
Thanks!
Seems like it is a known problem and will be fixed in v0.8