Skip to content

Commit

Permalink
improve deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Aug 29, 2019
1 parent 996278d commit 4d8a87f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 49 deletions.
36 changes: 18 additions & 18 deletions packages/store/addon/-private/system/core-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { promiseArray, promiseObject } from './promise-proxies';
import { _bind, _guard, _objectIsAlive, guardDestroyedStore } from './store/common';

import { normalizeResponseHelper } from './store/serializer-response';
import { serializerForAdapter } from './store/serializers';
import recordDataFor from './record-data-for';
import FetchManager, { SaveOp } from './fetch-manager';

Expand Down Expand Up @@ -3342,14 +3341,14 @@ abstract class CoreStore extends Service {

// no model specific serializer or application serializer, check for the `defaultSerializer`
// property defined on the adapter
if (DEBUG) {
deprecate('deprecate adapter.serializer and adapter.defaultSerializer fallbacks', false, {
id: 'ember-data:default-serializers',
until: '4.0',
});
}
let adapter = this.adapterFor(modelName);
let serializerName = get(adapter, 'defaultSerializer');

deprecate('deprecate adapter.serializer and adapter.defaultSerializer fallbacks', !serializerName, {
id: 'ember-data:default-serializers',
until: '4.0',
});

serializer = serializerName
? _serializerCache[serializerName] || owner.lookup(`serializer:${serializerName}`)
: undefined;
Expand Down Expand Up @@ -3383,12 +3382,6 @@ abstract class CoreStore extends Service {

// final fallback, no model specific serializer, no application serializer, no
// `serializer` property on store: use json-api serializer
if (DEBUG) {
deprecate('deprecate -default serializer fallback in store.serializerFor', false, {
id: 'ember-data:default-serializers',
until: '4.0',
});
}
serializer = _serializerCache['-default'] || owner.lookup('serializer:-default');
if (DEBUG && HAS_SERIALIZER_PACKAGE && serializer === undefined) {
const JSONSerializer = require('@ember-data/serializer/json').default;
Expand All @@ -3398,6 +3391,11 @@ abstract class CoreStore extends Service {
serializer && deprecateTestRegistration('serializer', '-default');
}

deprecate('deprecate -default serializer fallback in store.serializerFor', !serializer, {
id: 'ember-data:default-serializers',
until: '4.0',
});

assert(
`No serializer was found for '${modelName}' and no 'application' serializer was found as a fallback`,
serializer !== undefined
Expand Down Expand Up @@ -3491,12 +3489,14 @@ defineProperty(
CoreStore.prototype,
'defaultAdapter',
computed('adapter', function() {
if (DEBUG) {
deprecate('deprecate store.defaultAdapter (-json-api) and the -json-api adapter fallback behavior', false, {
deprecate(
'deprecate store.adapter, store.defaultAdapter (-json-api) and the -json-api adapter fallback behavior',
false,
{
id: 'ember-data:default-adapter',
until: '4.0',
});
}
}
);
let adapter = this.adapter || '-json-api';

assert(
Expand All @@ -3521,7 +3521,7 @@ function _commit(adapter, store, operation, snapshot) {
);

let promise = Promise.resolve().then(() => adapter[operation](store, modelClass, snapshot));
let serializer = serializerForAdapter(store, adapter, modelName);
let serializer = store.serializerFor(modelName);
let label = `DS: Extract and notify about ${operation} completion of ${internalModel}`;

assert(
Expand Down
7 changes: 3 additions & 4 deletions packages/store/addon/-private/system/fetch-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { assert, warn, inspect } from '@ember/debug';
import Snapshot from './snapshot';
import { guardDestroyedStore, _guard, _bind, _objectIsAlive } from './store/common';
import { normalizeResponseHelper } from './store/serializer-response';
import { serializerForAdapter } from './store/serializers';
import { InvalidError } from '@ember-data/adapter/error';
import coerceId from './coerce-id';
import { A } from '@ember/array';
Expand Down Expand Up @@ -115,7 +114,7 @@ export default class FetchManager {
);

let promise = Promise.resolve().then(() => adapter[operation](store, modelClass, snapshot));
let serializer = serializerForAdapter(store, adapter, modelName);
let serializer = store.serializerFor(modelName);
let label = `DS: Extract and notify about ${operation} completion of ${internalModel}`;

assert(
Expand Down Expand Up @@ -262,7 +261,7 @@ export default class FetchManager {
`You made a 'findRecord' request for a '${modelName}' with id '${id}', but the adapter's response did not have any data`,
!!payloadIsNotBlank(adapterPayload)
);
let serializer = serializerForAdapter(this._store, adapter, modelName);
let serializer = this._store.serializerFor(modelName);
let payload = normalizeResponseHelper(serializer, this._store, klass, adapterPayload, id, 'findRecord');
assert(
`Ember Data expected the primary data returned from a 'findRecord' response to be an object but instead it found an array.`,
Expand Down Expand Up @@ -379,7 +378,7 @@ export default class FetchManager {
`You made a 'findMany' request for '${modelName}' records with ids '[${ids}]', but the adapter's response did not have any data`,
!!payloadIsNotBlank(adapterPayload)
);
let serializer = serializerForAdapter(store, adapter, modelName);
let serializer = store.serializerFor(modelName);
let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findMany');
return payload;
},
Expand Down
10 changes: 4 additions & 6 deletions packages/store/addon/-private/system/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,12 +623,10 @@ const Model = EmberObject.extend(DeprecatedEvented, {
*/
toJSON(options) {
// container is for lazy transform lookups
if (DEBUG) {
deprecate('deprecate toJSON', false, {
id: 'ember-data:model.toJSON',
until: '4.0',
});
}
deprecate('deprecate toJSON', false, {
id: 'ember-data:model.toJSON',
until: '4.0',
});
let serializer = this._internalModel.store.serializerFor('-default');
let snapshot = this._internalModel.createSnapshot();

Expand Down
15 changes: 7 additions & 8 deletions packages/store/addon/-private/system/store/finders.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import coerceId from '../coerce-id';
import { _bind, _guard, _objectIsAlive, guardDestroyedStore } from './common';

import { normalizeResponseHelper } from './serializer-response';
import { serializerForAdapter } from './serializers';
import { assign } from '@ember/polyfills';
import { IDENTIFIERS } from '@ember-data/canary-features';
import { REQUEST_SERVICE } from '@ember-data/canary-features';
Expand Down Expand Up @@ -45,7 +44,7 @@ export function _find(adapter, store, modelClass, id, internalModel, options) {
`You made a 'findRecord' request for a '${modelName}' with id '${id}', but the adapter's response did not have any data`,
payloadIsNotBlank(adapterPayload)
);
let serializer = serializerForAdapter(store, adapter, modelName);
let serializer = store.serializerFor(modelName);
let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, id, 'findRecord');
assert(
`Ember Data expected the primary data returned from a 'findRecord' response to be an object but instead it found an array.`,
Expand Down Expand Up @@ -97,7 +96,7 @@ export function _findMany(adapter, store, modelName, ids, internalModels, option
`You made a 'findMany' request for '${modelName}' records with ids '[${ids}]', but the adapter's response did not have any data`,
payloadIsNotBlank(adapterPayload)
);
let serializer = serializerForAdapter(store, adapter, modelName);
let serializer = store.serializerFor(modelName);
let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findMany');
return store._push(payload);
},
Expand Down Expand Up @@ -280,7 +279,7 @@ export function _findHasMany(adapter, store, internalModel, link, relationship,
`You made a 'findHasMany' request for a ${internalModel.modelName}'s '${relationship.key}' relationship, using link '${link}' , but the adapter's response did not have any data`,
payloadIsNotBlank(adapterPayload)
);
let serializer = serializerForAdapter(store, adapter, relationship.type);
let serializer = store.serializerFor(relationship.type);
let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findHasMany');

syncRelationshipDataFromLink(store, payload, internalModel, relationship);
Expand All @@ -305,7 +304,7 @@ export function _findBelongsTo(adapter, store, internalModel, link, relationship

return promise.then(
adapterPayload => {
let serializer = serializerForAdapter(store, adapter, relationship.type);
let serializer = store.serializerFor(relationship.type);
let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findBelongsTo');

if (!payload.data) {
Expand Down Expand Up @@ -336,7 +335,7 @@ export function _findAll(adapter, store, modelName, options) {
`You made a 'findAll' request for '${modelName}' records, but the adapter's response did not have any data`,
payloadIsNotBlank(adapterPayload)
);
let serializer = serializerForAdapter(store, adapter, modelName);
let serializer = store.serializerFor(modelName);
let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findAll');

store._push(payload);
Expand All @@ -360,7 +359,7 @@ export function _query(adapter, store, modelName, query, recordArray, options) {

return promise.then(
adapterPayload => {
let serializer = serializerForAdapter(store, adapter, modelName);
let serializer = store.serializerFor(modelName);
let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'query');
let internalModels = store._push(payload);

Expand Down Expand Up @@ -395,7 +394,7 @@ export function _queryRecord(adapter, store, modelName, query, options) {

return promise.then(
adapterPayload => {
let serializer = serializerForAdapter(store, adapter, modelName);
let serializer = store.serializerFor(modelName);
let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'queryRecord');

assert(
Expand Down
13 changes: 0 additions & 13 deletions packages/store/addon/-private/system/store/serializers.js

This file was deleted.

0 comments on commit 4d8a87f

Please sign in to comment.