Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] remove all stale feature flags #5384

Merged
merged 2 commits into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 1 addition & 123 deletions FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,126 +11,4 @@ entry in `config/features.json`.

## Feature Flags

- `ds-improved-ajax` [#3099](https://github.com/emberjs/data/pull/3099)

This feature allows to customize how a request is formed by overwriting
`methodForRequest`, `urlForRequest`, `headersForRequest` and `bodyForRequest`
in the `DS.RESTAdapter`.

- `ds-pushpayload-return` [#4110](https://github.com/emberjs/data/pull/4110)

Enables `pushPayload` to return the model(s) that are created or
updated via the internal `store.push`.

- `ds-payload-type-hooks` [#4318](https://github.com/emberjs/data/pull/4318)

Adds two new hooks `modelNameFromPayloadType` and `payloadTypeFromModelName`
hooks to the serializers. They are used to map a custom type in the payload
to the Ember-Data model name and vice versa.

It also deprecates `modelNameFromPayloadKey` and `payloadKeyFromModelName`
for the JSONSerializer and JSONAPISerializer: those payloads don't have
_keys_ which represent a model name. Only the keys in the payload for a
RESTSerializer represent model names, so the `payloadKeyFromModelName` and
`modelNameFromPayloadKey` are available in that serializer.

```js
// rest response
{
"blog/post": {
"id": 1,
"user": 1,
"userType": "api::v1::administrator"
}
}

// RESTSerializer invokes the following hooks
restSerializer.modelNameFromPayloadKey("blog/post");
restSerializer.modelNameFromPayloadType("api::v1::administrator");
```

```js
// json-api response
{
"data": {
"id": 1,
"type": "api::v1::administrator",
"relationships": {
"supervisor": {
"data": {
"id": 1,
"type": "api::v1::super-user"
}
}
}
}
}

// JSONAPISerializer invokes the following hooks
jsonApiSerializer.modelNameFromPayloadType("api::v1::administrator");
jsonApiSerializer.modelNameFromPayloadType("api::v1::super-user");
```

- `ds-overhaul-references` [#4398](https://github.com/emberjs/data/pull/4398)

This tackles some inconsistencies within `push()` on references. It should
only be used to push a JSON-API payload. The following use cases are
addressed and deprecated:

- `BelongsToReference#push()` accepts a `DS.Model`
- `HasManyReference#push()` accepts a plain array
- `HasManyReference#push()` accepts a pseudo-JSON-API format:

```js
{
data: [
{ data: { type: 'model', id: 1 } }
]
}
```

- `ds-check-should-serialize-relationships` [#4279](https://github.com/emberjs/data/pull/4279)

Adds public method for `shouldSerializeHasMany`, used to determine if a
`hasMany` relationship can be serialized.

- `ds-rollback-attribute` [#4246](https://github.com/emberjs/data/pull/4246)

Adds a `rollbackAttribute` method to models. Similar to `rollbackAttributes`,
but for only a single attribute.

```js
// { firstName: 'Tom', lastName: 'Dale' }
let tom = store.peekRecord('person', 1);

tom.setProperties({
firstName: 'Yehuda',
lastName: 'Katz'
});

tom.rollbackAttribute('firstName') // { firstName: 'Tom', lastName: 'Katz' }
tom.get('hasDirtyAttributes') // true

tom.rollbackAttribute('lastName') // { firstName: 'Tom', lastName: 'Dale' }
tom.get('hasDirtyAttributes') // false
```

- `ds-serialize-id` [#4620](https://github.com/emberjs/data/pull/4620)

Adds a `serializeId` method to JSONSerializer.

```js
// app/serializers/application.js
import DS from 'ember-data';

export default DS.JSONSerializer.extend({
serializeId(snapshot, json, primaryKey) {
var id = snapshot.id;
json[primaryKey] = parseInt(id, 10);
}
});
```
- `ds-deprecate-store-serialize` [#4654](https://github.com/emberjs/data/pull/4654)

Adds a deprecation warning when using Store#serialize(record) method.
You can use record.serialize() instead.
- None currently.
18 changes: 0 additions & 18 deletions addon/-private/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { assert, inspect } from '@ember/debug';
import RootState from "./states";
import Relationships from "../relationships/state/create";
import Snapshot from "../snapshot";
import isEnabled from '../../features';
import OrderedSet from "../ordered-set";

import { getOwner } from '../../utils';
Expand Down Expand Up @@ -1249,20 +1248,3 @@ export default class InternalModel {
return reference;
}
}

if (isEnabled('ds-rollback-attribute')) {
/*
Returns the latest truth for an attribute - the canonical value, or the
in-flight value.

@method lastAcknowledgedValue
@private
*/
InternalModel.prototype.lastAcknowledgedValue = function lastAcknowledgedValue(key) {
if (key in this._inFlightAttributes) {
return this._inFlightAttributes[key];
} else {
return this._data[key];
}
};
}
26 changes: 0 additions & 26 deletions addon/-private/system/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { DEBUG } from '@glimmer/env';
import { assert, warn } from '@ember/debug';
import { PromiseObject } from "../promise-proxies";
import Errors from "../model/errors";
import isEnabled from '../../features';
import RootState from '../model/states';
import {
relationshipsByNameDescriptor,
Expand Down Expand Up @@ -1842,31 +1841,6 @@ Model.reopenClass({
}
});

if (isEnabled('ds-rollback-attribute')) {
Model.reopen({
/**
Discards any unsaved changes to the given attribute. This feature is not enabled by default. You must enable `ds-rollback-attribute` and be running a canary build.

Example

```javascript
record.get('name'); // 'Untitled Document'
record.set('name', 'Doc 1');
record.get('name'); // 'Doc 1'
record.rollbackAttribute('name');
record.get('name'); // 'Untitled Document'
```

@method rollbackAttribute
*/
rollbackAttribute(attributeName) {
if (attributeName in this._internalModel._attributes) {
this.set(attributeName, this._internalModel.lastAcknowledgedValue(attributeName));
}
}
});
}

if (DEBUG) {
Model.reopen({
// This is a temporary solution until we refactor DS.Model to not
Expand Down
8 changes: 0 additions & 8 deletions addon/-private/system/references/belongs-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { resolve } from 'rsvp';
import Model from '../model/model';
import Reference from './reference';

import isEnabled from '../../features';
import { deprecate } from '@ember/debug';
import { assertPolymorphicType } from 'ember-data/-debug';

/**
Expand Down Expand Up @@ -241,12 +239,6 @@ export default class BelongsToReference extends Reference {
let record;

if (data instanceof Model) {
if (isEnabled('ds-overhaul-references')) {
deprecate("BelongsToReference#push(DS.Model) is deprecated. Update relationship via `model.set('relationshipName', value)` instead.", false, {
id: 'ds.references.belongs-to.push-record',
until: '4.0.0'
});
}
record = data;
} else {
record = this.store.push(data);
Expand Down
50 changes: 7 additions & 43 deletions addon/-private/system/references/has-many.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { A } from '@ember/array';
import { resolve } from 'rsvp';
import { get } from '@ember/object';
import Reference from './reference';
import { DEBUG } from '@glimmer/env';
import { deprecate } from '@ember/debug';
import { assertPolymorphicType } from 'ember-data/-debug';

import isEnabled from '../../features';

/**
A HasManyReference is a low level API that allows users and addon
author to perform meta-operations on a has-many relationship.
Expand Down Expand Up @@ -239,53 +235,21 @@ export default class HasManyReference extends Reference {
return resolve(objectOrPromise).then((payload) => {
let array = payload;

if (isEnabled("ds-overhaul-references")) {
deprecate("HasManyReference#push(array) is deprecated. Push a JSON-API document instead.", !Array.isArray(payload), {
id: 'ds.references.has-many.push-array',
until: '4.0.0'
});
}

let useLegacyArrayPush = true;
if (typeof payload === "object" && payload.data) {
array = payload.data;
useLegacyArrayPush = array.length && array[0].data;

if (isEnabled('ds-overhaul-references')) {
deprecate("HasManyReference#push() expects a valid JSON-API document.", !useLegacyArrayPush, {
id: 'ds.references.has-many.push-invalid-json-api',
until: '4.0.0'
});
}
}

if (!isEnabled('ds-overhaul-references')) {
useLegacyArrayPush = true;
}

let internalModels;
if (useLegacyArrayPush) {
internalModels = array.map((obj) => {
let record = this.store.push(obj);

if (DEBUG) {
let relationshipMeta = this.hasManyRelationship.relationshipMeta;
assertPolymorphicType(this.internalModel, relationshipMeta, record._internalModel);
}

return record._internalModel;
});
} else {
let records = this.store.push(payload);
internalModels = A(records).mapBy('_internalModel');
internalModels = array.map((obj) => {
let record = this.store.push(obj);

if (DEBUG) {
internalModels.forEach((internalModel) => {
let relationshipMeta = this.hasManyRelationship.relationshipMeta;
assertPolymorphicType(this.internalModel, relationshipMeta, internalModel);
});
let relationshipMeta = this.hasManyRelationship.relationshipMeta;
assertPolymorphicType(this.internalModel, relationshipMeta, record._internalModel);
}
}

return record._internalModel;
});

this.hasManyRelationship.computeChanges(internalModels);

Expand Down
18 changes: 6 additions & 12 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import { getOwner } from '../utils';
import coerceId from "./coerce-id";
import RecordArrayManager from "./record-array-manager";
import InternalModel from "./model/internal-model";
import isEnabled from '../features';

const badIdFormatAssertion = '`id` passed to `findRecord()` has to be non-empty string or number';

Expand Down Expand Up @@ -273,12 +272,11 @@ Store = Service.extend({
@param {Object} options an options hash
*/
serialize(record, options) {
if (isEnabled('ds-deprecate-store-serialize')) {
deprecate('Use of store.serialize is deprecated, use record.serialize instead.', false, {
id: 'ds.store.serialize',
until: '3.0'
});
}
deprecate('Use of store.serialize is deprecated, use record.serialize instead.', false, {
id: 'ds.store.serialize',
until: '3.0'
});

let snapshot = record._internalModel.createSnapshot();
return snapshot.serialize(options);
},
Expand Down Expand Up @@ -2525,11 +2523,7 @@ Store = Service.extend({
let normalizedModelName = normalizeModelName(modelName);
serializer = this.serializerFor(normalizedModelName);
}
if (isEnabled('ds-pushpayload-return')) {
return serializer.pushPayload(this, payload);
} else {
serializer.pushPayload(this, payload);
}
serializer.pushPayload(this, payload);
},

/**
Expand Down
Loading