I use Ractive to display data from a constantly changing array (received from PouchDB) with the magic: trueparameter. That worked fine until in Version 0.9.x this parameter was no longer available.
So it is advised to use ractive.update()every time my array changes. The problem I'm facing seems quite simple, but I'm fairly inexperienced:
For tracking the changes I do roughly the following (taken from a PouchDB script):
fetchInitialDocs().then(renderDocsSomehow).then(reactToChanges).catch(console.log.bind(console));
function renderDocsSomehow() {
let myRactive = new Ractive({
el: '#myDiv',
template: 'my Template',
//magic: true,
data:{
doc1: docs
},
components: {myComponents},
computed: {computedValues}
});
}
function reactToChanges() {
//here my changes appear
onUpdatedOrInserted(change.doc);
myRactive.update() // <- I cannot use update here because "myRactive" is not known at this point.
}
What I tried also was setting an observer in the renderDocsSomehow() function
ractive.observe('doc1', function(newValue, oldValue, keypath) {
ractive.update()
});
but this did not do the trick.
So how can I inform Ractive that my data has changed and it needs to update itself?
If
reactToChangesis just a function that sets up "listeners" formyRactiveand is never called elsewhere, you can probably put the code for it in anoninit. This way, you have access to the instance.