How to use the rsvp.default.resolve 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 / addon / -private / system / store.js View on Github external
_findBelongsToByJsonApiResource(resource, parentInternalModel, relationshipMeta, options) {
    if (!resource) {
      return RSVP.resolve(null);
    }

    // TODO not this
    let hasData = resource.data !== null;
    let internalModel = hasData ? this._internalModelForResource(resource.data) : null;
    let {
      isStale: relationshipIsStale,
      hasReceivedData: hasAnyRelationshipData,
      isEmpty: relationshipIsEmpty,
    } = resource.getState();
    // TODO probably a better thing to check here than this
    let hasDematerializedInverse = hasData ? internalModel.isEmpty() : false;
    let allInverseRecordsAreLoaded = hasData ? !internalModel.isEmpty() : true;
    hasAnyRelationshipData = hasAnyRelationshipData || parentInternalModel.isNew();

    let shouldFindViaLink =
github emberjs / data / addon / -private / system / store.js View on Github external
_findHasManyByJsonApiResource(resource, parentInternalModel, relationshipMeta, options) {
    if (!resource) {
      return RSVP.resolve([]);
    }

    let hasResourceData = Array.isArray(resource.data) && resource.data.length > 0;
    let internalModels = hasResourceData
      ? resource.data.map(i => this._internalModelForResource(i))
      : [];
    let {
      isStale: relationshipIsStale,
      hasReceivedData: hasAnyRelationshipData,
      isEmpty: relationshipIsEmpty,
    } = resource.getState();
    // TODO probably a better thing to check here than this
    let hasDematerializedInverse = hasResourceData
      ? internalModels.reduce((c, i) => c || i.isEmpty(), false)
      : false;
    let allInverseRecordsAreLoaded = hasResourceData
github emberjs / data / packages / store / addon / -private / system / core-store.ts View on Github external
return this.findMany(internalModels, options);
    }

    let hasData = hasAnyRelationshipData && !relationshipIsEmpty;

    // fetch by data
    if (hasData || hasLocalPartialData) {
      let internalModels = resource.data.map(json => this._internalModelForResource(json));

      return this._scheduleFetchMany(internalModels, options);
    }

    // we were explicitly told we have no data and no links.
    //   TODO if the relationshipIsStale, should we hit the adapter anyway?
    return RSVP.resolve([]);
  },
github emberjs / data / packages / store / addon / -private / system / core-store.ts View on Github external
_fetchBelongsToLinkFromResource(resource, parentInternalModel, relationshipMeta, options) {
    if (!resource || !resource.links || !resource.links.related) {
      // should we warn here, not sure cause its an internal method
      return RSVP.resolve(null);
    }
    return this.findBelongsTo(
      parentInternalModel,
      resource.links.related,
      relationshipMeta,
      options
    ).then(internalModel => {
      let response = internalModel && recordDataFor(internalModel).getResourceIdentifier();
      parentInternalModel.linkWasLoadedForRelationship(relationshipMeta.key, { data: response });
      if (internalModel === null) {
        return null;
      }
      // TODO Igor this doesn't seem like the right boundary, probably the caller method should extract the record out
      return internalModel.getRecord();
    });
  },
github emberjs / data / addon / -private / system / store.js View on Github external
// fetch using data, pulling from local cache if possible
    if (!relationshipIsStale && (preferLocalCache || hasLocalPartialData)) {
      /*
        We have canonical data, but our local state is empty
       */
      if (localDataIsEmpty) {
        return RSVP.resolve(null);
      }

      return this._findByInternalModel(internalModel, options);
    }

    let resourceIsLocal = !localDataIsEmpty && resource.data.id === null;

    if (resourceIsLocal) {
      return RSVP.resolve(internalModel.getRecord());
    }

    // fetch by data
    if (!localDataIsEmpty) {
      return this._scheduleFetch(internalModel, options).then(() => {
        return internalModel.getRecord();
      });
    }

    // we were explicitly told we have no data and no links.
    //   TODO if the relationshipIsStale, should we hit the adapter anyway?
    return RSVP.resolve(null);
  },
github emberjs / data / packages / store / addon / -private / system / core-store.ts View on Github external
// fetch using data, pulling from local cache if possible
    if (!relationshipIsStale && (preferLocalCache || hasLocalPartialData)) {
      /*
        We have canonical data, but our local state is empty
       */
      if (localDataIsEmpty) {
        return RSVP.resolve(null);
      }

      return this._findByInternalModel(internalModel, options);
    }

    let resourceIsLocal = !localDataIsEmpty && resource.data.id === null;

    if (resourceIsLocal) {
      return RSVP.resolve(internalModel.getRecord());
    }

    // fetch by data
    if (!localDataIsEmpty) {
      return this._scheduleFetch(internalModel, options).then(() => {
        return internalModel.getRecord();
      });
    }

    // we were explicitly told we have no data and no links.
    //   TODO if the relationshipIsStale, should we hit the adapter anyway?
    return RSVP.resolve(null);
  },