ember-data: fix error when using async/await

This commit is contained in:
Derek Wickern
2018-01-27 19:04:30 -08:00
parent 831b49efaf
commit d4db791802
2 changed files with 32 additions and 2 deletions

View File

@@ -854,7 +854,7 @@ declare module "ember-data" {
*/
interface PromiseArray<T>
extends Ember.ArrayProxy<T>,
Ember.PromiseProxyMixin<PromiseArray<T>> {}
Ember.PromiseProxyMixin<Ember.ArrayProxy<T>> {}
class PromiseArray<T> {}
/**
* A `PromiseObject` is an object that acts like both an `Ember.Object`
@@ -865,7 +865,7 @@ declare module "ember-data" {
*/
interface PromiseObject<T>
extends Ember.ObjectProxy,
Ember.PromiseProxyMixin<T & PromiseObject<T>> {}
Ember.PromiseProxyMixin<T & Ember.ObjectProxy> {}
class PromiseObject<T> {}
/**
* A PromiseManyArray is a PromiseArray that also proxies certain method calls

View File

@@ -4,8 +4,10 @@ import { assertType } from "./lib/assert";
declare const store: DS.Store;
class Comment extends DS.Model {}
class Post extends DS.Model {
title = DS.attr('string');
comments = DS.hasMany<Comment>('comment');
}
let post = store.createRecord<Post>('post', {
@@ -74,6 +76,34 @@ const MyRoute = Ember.Route.extend({
}
});
const MyRouteAsync = Ember.Route.extend({
async beforeModel(): Promise<Ember.Array<DS.Model>> {
const store = Ember.get(this, 'store');
return await store.findAll('someStoreRecord');
},
async model(): Promise<DS.Model> {
const store = this.get('store');
return await store.findRecord('someStoreRecord', 1);
},
async afterModel(): Promise<Ember.Array<Comment>> {
const post = await this.get('store').findRecord<Post>('post', 1);
return await post.get('comments');
}
});
class MyRouteAsyncES6 extends Ember.Route {
async beforeModel(): Promise<Ember.Array<DS.Model>> {
return await this.store.findAll('someStoreRecord');
}
async model(): Promise<DS.Model> {
return await this.store.findRecord('someStoreRecord', 1);
}
async afterModel(): Promise<Ember.Array<Comment>> {
const post = await this.store.findRecord<Post>('post', 1);
return await post.get('comments');
}
}
// GET to /users?filter[email]=tomster@example.com
const tom = store.query('user', {
filter: {