Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
});
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;
})
});
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);
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(),
get otp () {
return DS.PromiseObject.create({
promise: this.api.request('/lectures/otp', {
data: {
videoId: this.lecture.videoId,
sectionId: this.sectionId,
runAttemptId: this.runAttempt.id
}
})
})
}
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 });
}
}),
progress: computed('runAttempt', function () {
return DS.PromiseObject.create({
promise: this.api.request(`run_attempts/${this.runAttempt.id}/progress`)
})
}),
certificateNotPresent: not('runAttempt.certificate'),
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
})
}),
get progress() {
return DS.PromiseObject.create({
promise: this.api.request(`run_attempts/${this.runAttempt.id}/progress`)
})
}
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')
});