How to use the ember-data.PromiseObject 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 linxmix / linx / app / lib / models / dependent-model.js View on Github external
params[typeKey] = Ember.computed('isLoaded', privateKey, function() {
      var typeId = this.get('_data.' + privateKey);

      // TODO(AFTERPROMISE): refactor this
      var cached;
      while (!(cached = this.get(cacheKey))) {
        this.set(cacheKey, DS.PromiseObject.create({
          promise: new Ember.RSVP.Promise((resolve, reject) => {

            // if we dont have this model, create one and save it
            if (this.get('isLoaded') && !typeId) {
              var model = this.get('store').createRecord(typeKey);
              this.set(privateKey, model);
              resolve(model);
            } else {
              this.get(privateKey).then(resolve, reject);
            }
          }),
        }));
      }

      return cached
    });
github usecanvas / canvas-editor / addon / components / canvas-block-card / component.js View on Github external
unfurled: computed('block', function() {
    const block = this.get('block');
    const promise =  DS.PromiseObject.create({
      promise: this.get('unfurl')(block).then(unfurled => {
        this.get('cardDidLoad')();
        block.set('unfurled', unfurled);
        return unfurled;
      })
    });
    // Catch error thrown by the PromiseProxy to not trigger error notification
    promise.catch(Ember.K);
    return promise;
  })
});
github jichu4n / asciidoclive / client / app / utils / dropbox-storage-provider.js View on Github external
load(storagePath) {
    return DS.PromiseObject.create({
      promise: this.authenticate().then(function() {
        return new Ember.RSVP.Promise(function(resolve, reject) {
          this.get('client').readFile(
            storagePath, function(error, fileContent) {
              if (error) {
                reject(error);
              } else {
                var doc = this.get('store').createRecord('doc', {
                  title: storagePath.split('/').pop(),
                  body: fileContent,
                  storageSpec: StorageSpec.create({
                    storageType: this.get('storageType'),
                    storagePath: storagePath
                  })
                });
                resolve(doc);
github linuxenko / umediashare / app / models / device.js View on Github external
clientProtocol : function() {
    return DS.PromiseObject.create({
     promise: new Ember.RSVP.Promise((resolve, reject) => {
          this.get('client').callAction('ConnectionManager', 'GetProtocolInfo', { },function(err, description) {
            if (description.Sink) {
              resolve(description.Sink.split(','));
            } else {
              reject('wrong data');
            }
          });
        })
    });
  }.property(),
github coding-blocks / codingblocks.online.projectx / app / pods / components / vdo-player / component.js View on Github external
get otp () {
    return DS.PromiseObject.create({
      promise: this.api.request('/lectures/otp', {
        data: {
          videoId: this.lecture.videoId,
          sectionId: this.sectionId,
          runAttemptId: this.runAttempt.id
        }
      })
    })
  }
github linxmix / linx / app / models / track / audio-binary.js View on Github external
decodedArrayBuffer: Ember.computed('audioContext', 'arrayBuffer', function() {
    let { arrayBuffer, audioContext } = this.getProperties('arrayBuffer', 'audioContext');

    if (arrayBuffer) {
      let promise = arrayBuffer.then((arrayBuffer) => {
        return new Ember.RSVP.Promise((resolve, reject) => {
          audioContext.decodeAudioData(arrayBuffer, resolve, (error) => {
            Ember.Logger.log('AudioSource Decoding Error: ' + error.err);
            reject(error);
          });
        });
      });

      return DS.PromiseObject.create({ promise });
    }
  }),
github coding-blocks / codingblocks.online.projectx / app / pods / components / certificate-comp / component.js View on Github external
progress: computed('runAttempt', function () {
    return DS.PromiseObject.create({
      promise: this.api.request(`run_attempts/${this.runAttempt.id}/progress`)
    })
  }),
  certificateNotPresent: not('runAttempt.certificate'),
github coding-blocks / codingblocks.online.projectx / app / pods / components / goodie-comp / component.js View on Github external
thresholdCompleted: computed('statusInProgress','alreadyClaimed','progress', 'run.goodiesThreshold', function () {
        const thresholdCompleted = this.progress.then(progress => {
            return progress.completedContents / progress.totalContents > (this.get('run.goodiesThreshold')/100)
        })
        return DS.PromiseObject.create({
            promise: thresholdCompleted
        })
    }),
github coding-blocks / codingblocks.online.projectx / app / pods / classroom / timeline / controller.js View on Github external
get progress() {
    return DS.PromiseObject.create({
      promise: this.api.request(`run_attempts/${this.runAttempt.id}/progress`)
    })
  }
github linuxenko / umediashare / app / models / playlist.js View on Github external
itemTypes : function() {
    let types = new Set();

    return DS.PromiseObject.create({
       promise : this.get('store').query('playlistItem', {playlist : this.get('id')}).then( r => {
                  r.forEach( i => {
                    types.add(i.get('type'));
                  });
                 return Array.from(types);
              })
    });
  }.property('itemsNum')
});