Sorry - once again about subscriptions etc... :-)

Hi everybody,

I’m still wrapping my head around subscriptions - or trying to, anyway…

I think I understand how they work if you need to render something to a template. You do a .ready(), and push the collection to the template, that will render docs that are in your (local) collection. Fine :smile:

But now: if I understand correctly, when I subscribe to a collection I (might) get a partial dataset. I might not get all of it. So if I do a find(), I might not get an answer, but I might need to wait for it, presumably with some callback mechanism. Fine. But I cannot find any example for this. All examples seem to focus on rendering too the template. But what if I do not want to do that? What if I need a item from the db (from a large, thus presumably not fully loaded?) table. I want to use that item for a calculation. And I do not care if it takes 0.1 second to load from the server, but I do need that item. How to go about this? I cannot tell from the documentation how to do that…

Other than, maybe, use a reactiveVar, and look for the onchange in that var, or something like that. But that does feel… convulted :smiley:
Probably I missed something in some document - please point me in the right direction? :grin:

Paul

not fully sure what you’re doing, but it seems to me that you should do your calculations reactively. So it wouldn’t matter if the document is loaded or not - the calculation will update itself as the new data arrives.

Calculations in general are cheap to process for a computer.

In the most simplest terms do your calculations in the helper of the template.

Hi Krister,

well, suppose I need to multiply 2 numbers, both from the same dataset, but in different documents.
In that case I would need 2 reactiveVars, wait for them, and then do the calculation.
Is there no possible way to do:

collection.find({query1}).ready( function(){
  collecion.find({query2}).ready( function(){
    doSomethingMeaningfullAndTellTheUserAboutIt
  }
}

:triumph: ?
With two numbers, that might be doable using reactiveVars, but what if I need even more?
In my application I need to fetch objects from the database, instantiate them as JS-objects, and then perform actions on them. But of course, before instantiating them means being sure I got them in the first place :slight_smile: