I am using promises, but the problem is less fetching things asynchronously, and more my understanding of at what point I can embed things, and if I have to at all.
I guess what I mean is, at what point would I load myObjects? They are not initially embedded in the first object, and I only want to load them when they’re visually needed.
I guess an example would be a good idea.
So, say I have my array of users:
[
{
id: 0,
someOtherJunk: "blah",
child: 1
}
]
Even if the object has only one reference to another object;
Let’s say I go to /user/0
and it is set up to return exactly what I have up there.
My template looks something like this:
{{id}}
{{someOtherJunk}}
This item's child:
{{render child}}
How would I get that render statement to work?
Where could I load in child
as an object?
I can’t just infinitely load all things linked to it, as it’s all shaped like a rather expansive graph. I am only interested in loading nearest neighbours.
I could obviously create another field in the first object called itemObj
or something like that and stick the actual, loaded object in there, but how would I trigger it to load?
Would an elegant solution be to, on load, change all references in the object to functions, which would act as promises, and when called by something in the template load the object for you?
As for promises, I currently have App.Item.find()
doing that.
This is why my initial idea of overriding the {{render}}
helper and integrating asynchronous loading directly into it came into play.