Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
scheduleSave(internalModel, options) {
let promiseLabel = 'DS: Model#save ' + this;
let resolver = RSVP.defer(promiseLabel);
let recordData: RelationshipRecordData = internalModel._recordData;
if (recordData.isNew() && recordData.isDeleted()) {
// TODO should probably warn here
resolver.resolve();
return resolver.promise;
}
internalModel._recordData.willCommit();
//TODO Remove
internalModel.send('willCommit');
let promise = this._fetchManager.scheduleSave(identifierFor(internalModel), options);
promise = promise.then(payload => {
/*
Note to future spelunkers hoping to optimize.
}
// We already have a pending fetch for this
if (this._pendingFetch.has(identifier.type) && this._pendingFetch.get(identifier.type).find((fetch) => fetch.identifier.id === identifier.id)) {
return this._pendingFetch.get(identifier.type).find((fetch) => fetch.identifier.id === identifier.id).resolver.promise;
}
/*
if (internalModel._promiseProxy) {
return internalModel._promiseProxy;
}
*/
let id = identifier.id;
let modelName = identifier.type;
let resolver = RSVP.defer(`Fetching ${modelName}' with id: ${id}`);
let pendingFetchItem: PendingFetchItem = {
identifier,
resolver,
options,
queryRequest
};
if (DEBUG) {
if (shouldTrace) {
let trace;
try {
throw new Error(`Trace Origin for scheduled fetch for ${modelName}:${id}.`);
} catch (e) {
trace = e;
}
};
let pendingFetches = this._pendingFetch.get(identifier.type);
// We already have a pending fetch for this
if (pendingFetches) {
let matchingPendingFetch = pendingFetches.find(fetch => fetch.identifier.id === identifier.id);
if (matchingPendingFetch) {
return matchingPendingFetch.resolver.promise;
}
}
let id = identifier.id;
let modelName = identifier.type;
let resolver = RSVP.defer(`Fetching ${modelName}' with id: ${id}`);
let pendingFetchItem: PendingFetchItem = {
identifier,
resolver,
options,
queryRequest,
};
if (DEBUG) {
if (shouldTrace) {
let trace;
try {
throw new Error(`Trace Origin for scheduled fetch for ${modelName}:${id}.`);
} catch (e) {
trace = e;
}
scheduleSave(identifier: RecordIdentifier, options: any = {}): RSVP.Promise {
let promiseLabel = 'DS: Model#save ' + this;
let resolver = RSVP.defer(promiseLabel);
let query: SaveRecordMutation = {
op: 'saveRecord',
recordIdentifier: identifier,
options,
};
let queryRequest: Request = {
data: [query],
};
let snapshot = new Snapshot(options, identifier, this._store);
let pendingSaveItem = {
snapshot: snapshot,
resolver: resolver,
identifier,
options,
_scheduleFetch(internalModel, options) {
if (internalModel._promiseProxy) {
return internalModel._promiseProxy;
}
let { id, modelName } = internalModel;
let resolver = RSVP.defer(`Fetching ${modelName}' with id: ${id}`);
let pendingFetchItem = {
internalModel,
resolver,
options,
};
if (DEBUG) {
if (this.generateStackTracesForTrackedRequests === true) {
let trace;
try {
throw new Error(`Trace Origin for scheduled fetch for ${modelName}:${id}.`);
} catch (e) {
trace = e;
}
_scheduleFetch(internalModel, options) {
if (internalModel._promiseProxy) {
return internalModel._promiseProxy;
}
let { id, modelName } = internalModel;
let resolver = RSVP.defer(`Fetching ${modelName}' with id: ${id}`);
let pendingFetchItem = {
internalModel,
resolver,
options,
};
if (DEBUG) {
if (this.generateStackTracesForTrackedRequests === true) {
let trace;
try {
throw new Error(`Trace Origin for scheduled fetch for ${modelName}:${id}.`);
} catch (e) {
trace = e;
}
scheduleSave(identifier: RecordIdentifier, options: any) {
let promiseLabel = 'DS: Model#save ' + this;
let resolver = RSVP.defer(promiseLabel);
let query: SaveRecordExpression = {
'op': 'saveRecord',
record: identifier,
options
}
let queryRequest: QueryRequest = {
query
}
let snapshot = new Snapshot(options, identifier, this._store);
let pendingSaveItem = {
snapshot: snapshot,
resolver: resolver,
identifier,
options,