Skip to content

Commit

Permalink
chore: refactor store to class (#6249)
Browse files Browse the repository at this point in the history
* chore: convert store to class synta
  • Loading branch information
runspired authored Jul 19, 2019
1 parent 663856b commit e356cce
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 187 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@types/ember__debug": "^3.0.3",
"@types/ember__test-helpers": "~0.7.8",
"@types/qunit": "^2.5.3",
"@types/rsvp": "^4.0.2",
"@types/rsvp": "^4.0.3",
"babel-eslint": "^10.0.2",
"broccoli-babel-transpiler": "^7.2.0",
"broccoli-concat": "^3.7.3",
Expand Down
3 changes: 2 additions & 1 deletion packages/-ember-data/tests/helpers/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export default function setupStore(options) {
registry.optionsForType('serializer', { singleton: false });
registry.optionsForType('adapter', { singleton: false });

owner.register('service:store', Store.extend({ adapter }));
const TestStore = Store.extend({ adapter });
owner.register('service:store', TestStore);
owner.register('serializer:-default', JSONAPISerializer);
owner.register('serializer:-json', JSONSerializer);
owner.register('serializer:-rest', RESTSerializer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,18 @@ module('integration/adapter/queries - Queries', function(hooks) {
});

testInDebug('The store asserts when query is made and the adapter responses with a single record.', function(assert) {
env = setupStore({ person: Person, adapter: DS.RESTAdapter });
env = setupStore({
person: Person,
adapter: DS.RESTAdapter,
});
store = env.store;
adapter = env.adapter;

adapter.query = function(store, type, query, recordArray) {
assert.equal(type, Person, 'the query method is called with the correct type');

return resolve({
data: [{ id: 1, type: 'person', attributes: { name: 'Peter Wagenet' } }],
data: { id: 1, type: 'person', attributes: { name: 'Peter Wagenet' } },
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export default class InternalModel {

save(options) {
let promiseLabel = 'DS: Model#save ' + this;
let resolver = RSVP.defer(promiseLabel);
let resolver = RSVP.defer<InternalModel>(promiseLabel);

this.store.scheduleSave(this, resolver, options);
return resolver.promise;
Expand Down
9 changes: 6 additions & 3 deletions packages/store/addon/-private/system/references/record.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import RSVP, { resolve } from 'rsvp';
import Reference from './reference';
import { Record } from '../../ts-interfaces/record';
import { JsonApiResource } from '../../ts-interfaces/record-data-json-api';
import { JsonApiDocument, SingleResourceDocument } from '../../ts-interfaces/ember-data-json-api';

/**
An RecordReference is a low-level API that allows users and
Expand Down Expand Up @@ -89,10 +92,10 @@ export default class RecordReference extends Reference {
```
@method push
@param objectOrPromise {Promise|Object}
@return RSVP.Promise<record> a promise for the value (record or relationship)
@param objectOrPromise a JSON:API ResourceDocument or a promise resolving to one
@return a promise for the value (record or relationship)
*/
push(objectOrPromise): RSVP.Promise<object> {
push(objectOrPromise: SingleResourceDocument | Promise<SingleResourceDocument>): RSVP.Promise<Record> {
return resolve(objectOrPromise).then(data => {
return this.store.push(data);
});
Expand Down
Loading

0 comments on commit e356cce

Please sign in to comment.