I'm creating a single page app and I run into some trouble. It's basically very simple. When I try to persist a new model (model A) it want to use a property of this model (model A.id) in the persistance of another model (model B). The property 'id' (model A.id) is supplied by the back-end.
If I use the following sequence;
then the property A.id will be present AFTER the sync() call on the data source. The a-synchronous nature of these calls will lead to the problem that when the call is being made to the otherDataSource.add method the property A.id is not yet set.
After an extensive search I thought of a solution using promises. Since I don't know how to implement these I looked at the source of the data source component. That is when I discovered that the data source already has some sort of promises built in. Would it be possible to supply me (and all readers of this forum) with an example of how to use the promises?
This problem is giving me massive headaches and I've been stuck with the development of my app for quite some time so some help would be very, very, very much appreciated! :)
If I use the following sequence;
var
A = dataSource.add({ dataObjectA });
dataSource.sync();
var
dataObjectB = {
'aId'
: A.id,
'otherData'
: [] };
var
B = otherDataSource.add({ dataObjectB });
dataSource.sync();
then the property A.id will be present AFTER the sync() call on the data source. The a-synchronous nature of these calls will lead to the problem that when the call is being made to the otherDataSource.add method the property A.id is not yet set.
After an extensive search I thought of a solution using promises. Since I don't know how to implement these I looked at the source of the data source component. That is when I discovered that the data source already has some sort of promises built in. Would it be possible to supply me (and all readers of this forum) with an example of how to use the promises?
This problem is giving me massive headaches and I've been stuck with the development of my app for quite some time so some help would be very, very, very much appreciated! :)