ReactiveArray
ReactiveArray copied to clipboard
How best to update ReactiveArray from autorun?
I want to synchronize a database array with a client array, so I want to do something like...
Template.dayModal.onCreated(function(){
this.myAvailabilities = new ReactiveArray();
var self = this;
this.autorun(function(){
var myDateInfo = Groups.findOne etc etc...;
// ideally:
self.myAvailabilities.set(myDateInfo.availabilityArray);
});
});
Should I just clear the ReactiveArray
, iterate through the source array and push each onto the ReactiveArray
?
I think you should use the collection directly and not through a reactive array. In your case it looks like the array is just a pass-through.
That's precisely what I was GOING to do, but I need to update this array (and at least one other reactively) via a click-and-drag user interaction, so there's no way I can do that fast enough with minimongo. Thoughts?
there's no way I can do that fast enough with minimongo
Just how many times per second are you going to insert/update the collection? Why?
Heh, I'm saying I would never try to update the collection with that kind of frequency. I need to update the UI reactively, though, while dragging. I could do it by hand (so to speak), but I wanted to leverage the reactive components.
I only need to update the collection on mouseup, but need to update the UI while dragging.
I'm very confused. What happens while you're dragging the mouse? Are you updating the array?
btw, I think the (uninformed) answer to your question is "clear the array and add the values again".
onmousemove: calculate a bunch of coordinates and update (reactive) array onmouseup: write final positions to collection
Elsewhere, there are two helpers that each read from this array to draw the UI, and that needs to happen reactively, of course.
I got this working with ReactiveArray
, but it's really slow; I haven't audited it yet.
I don't know. I do stuff like that all the time but I never have to insert/update an array on mouse move.