How to use the ember-data.PromiseArray function in ember-data

To help you get started, we’ve selected a few ember-data 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 adiwg / mdEditor / app / pods / components / input / md-select / component.js View on Github external
codelist: Ember.computed('objectArray', function() {
    const objArray = this.get('objectArray');
    let inList = new Ember.RSVP.Promise(function(resolve, reject) {
      // succeed
      resolve(objArray);
      // or reject
      reject(new Error('Couldn\'t create a promise.'));
    });
    let codeId = this.get('valuePath');
    let codeName = this.get('namePath');
    let tooltip = this.get('tooltipPath');
    let icons = this.get('icons');
    let defaultIcon = this.get('defaultIcon');
    let outList = Ember.A();

    return DS.PromiseArray.create({
      promise: inList.then(function(arr) {
        arr.forEach(function(item) {
          let newObject = {
            codeId: get(item, codeId),
            codeName: get(item, codeName),
            tooltip: false,
            icon: icons.get(item[codeName].toString()) || icons.get(
              defaultIcon)
          };
          if(tooltip) {
            newObject.tooltip = get(item, tooltip);
          }
          outList.pushObject(newObject);
        });

        return outList;
github escalant3 / ember-data-tastypie-adapter / addon / serializers / dta.js View on Github external
if (relationshipType === 'manyToNone' || relationshipType === 'manyToMany' || relationshipType === 'manyToOne') {
      if (this.isEmbedded(relationship)) {
        if (snapshot.hasMany(relationship.key)) {
          json[key] = snapshot.hasMany(relationship.key).map(function (embeddedSnapshot) {
            var data = embeddedSnapshot.record.serialize({includeId: true});
            return data;
          });
        } else {
          json[key] = [];
        }
      } else {
        var relationData = snapshot.hasMany(relationship.key);

        // We can't deal with promises here. We need actual data
        if (relationData instanceof DS.PromiseArray) {
          // We need the content of the promise. Make sure it is fulfilled
          if (relationData.get('isFulfilled')) {
            // Use the fulfilled array
            relationData = relationData.get('content');
          } else {
            // If the property hasn't been fulfilled then it hasn't changed.
            // Fall back to the internal data. It contains enough for relationshipToResourceUri.
            relationData = snapshot.hasMany(relationship.key).mapBy('id').map(function(_id) {
              return {id: _id};
            }) || [];
          }
        }

        json[key] = relationData.map(function (next){
          return this.relationshipToResourceUri(relationship, next, this.store);
        }, this);
github zzarcon / spotyness / app / services / musicman.js View on Github external
get() {
      return DS.PromiseArray.create({
        init() {
          var promise = new Ember.RSVP.Promise((resolve) => {
            var request = Ember.$.get(`${env.apiHost}/me/following?type=artist`);

            request.then((data) => resolve(data.artists.items.compact()));
          });

          this.set('promise', promise);
        }
     });
    }
  })
github zzarcon / spotyness / app / services / musicman.js View on Github external
get() {
      return DS.PromiseArray.create({
        init() {
          var promise = new Ember.RSVP.Promise((resolve) => {
            var request = Ember.$.get(`${env.apiHost}/browse/featured-playlists`);

            request.then((data) => resolve(data.playlists.items));
          });

          this.set('promise', promise);
        }
     });
    }
  }),
github HospitalRun / hospitalrun-frontend / app / mixins / patient-visits.js View on Github external
let futureAppointments = result.filter(function(data) {
        let startDate = get(data, 'startDate');
        return startDate && moment(startDate).isAfter(moment(visitDate), 'day');
      }).sortBy('startDate');
      if (!futureAppointments.length) {
        return null;
      }
      if (!outPatient) {
        let [appointment] = futureAppointments;
        return appointment;
      } else {
        return futureAppointments.slice(0, 3);
      }

    });
    return (outPatient) ? DS.PromiseArray.create({ promise }) : DS.PromiseObject.create({ promise });
  },
github linxmix / linx / app / lib / utils.js View on Github external
export const asResolvedPromise = function(returnedObject, PromiseTypeConstructor = DS.PromiseObject) {

  if (_.isArray(returnedObject)) {
    PromiseTypeConstructor = DS.PromiseArray;
  }

  return PromiseTypeConstructor.create({
    promise: new Ember.RSVP.Promise(function (resolve, reject) {
      resolve(returnedObject);
    })
  });
};
github ilios / frontend / app / models / learner-group.js View on Github external
allDescendantUsers: computed('users.[]', 'children.@each.users', function(){
    var deferred = Ember.RSVP.defer();
    this.get('users').then(users => {
      this.get('children').then(children => {
        map(children.mapBy('allDescendantUsers'), childUsers => {
          users.addObjects(childUsers);
        }).then(() => {
          deferred.resolve(users.uniq());
        });
      });
    });

    return DS.PromiseArray.create({
      promise: deferred.promise
    });
  }),
  usersOnlyAtThisLevel: computed('users.[]', 'allDescendants.[]', function(){
github aptible / dashboard.aptible.com / app / application / store.js View on Github external
findStacksFor(organization) {
    var organizationUrl = organization.get('data.links.self');
    let promise = this.find('stack').then(() => {
      return this.filter('stack', (stack) => {
        return stack.get('data.links.organization') === organizationUrl;
      });
    });

    return DS.PromiseArray.create({ promise });
  },
github ilios / frontend / app / components / programyear-competency-manager.js View on Github external
subCompetencies.sortBy('title');
            }
          }
        }
      ));
    });
    Ember.RSVP.all(promises).then(function(){
      var domains = domainIds.map(function(id){
        return domainContainer[id];
      }).filter(
        domain => domain.get('subCompetencies').length > 0
      ).sortBy('title');
      defer.resolve(domains);
    });

    return DS.PromiseArray.create({
      promise: defer.promise
    });
  }),
  selectedDomains: computed('selectedCompetencies.@each.domain', function(){
github ilios / frontend / app / components / programyear-competency-manager.js View on Github external
if(!subCompetencies.contains(competency)){
              subCompetencies.pushObject(competency);
              subCompetencies.sortBy('title');
            }
          }
        }
      ));
    });
    Ember.RSVP.all(promises).then(function(){
      var domains = domainIds.map(function(id){
        return domainContainer[id];
      }).sortBy('title');
      defer.resolve(domains);
    });

    return DS.PromiseArray.create({
      promise: defer.promise
    });
  }),
  actions: {