How to use the rsvp.default.defer function in rsvp

To help you get started, we’ve selected a few rsvp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github emberjs / data / packages / store / addon / -private / system / core-store.ts View on Github external
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.
github emberjs / data / addon / -private / system / fetch-manager.ts View on Github external
}

    // 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;
        }
github emberjs / data / packages / store / addon / -private / system / fetch-manager.ts View on Github external
};

    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;
        }
github emberjs / data / packages / store / addon / -private / system / fetch-manager.ts View on Github external
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,
github emberjs / data / addon / -private / system / store.js View on Github external
_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;
        }
github emberjs / data / addon / -legacy-private / system / store.js View on Github external
_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;
        }
github emberjs / data / addon / -private / system / fetch-manager.ts View on Github external
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,