Skip to content

Commit

Permalink
Fix deprecated assign usage from @ember/assign (#7722)
Browse files Browse the repository at this point in the history
* Fix deprecated assign usage from @ember/assign

* assign -> Object.assign

* fix with Object.assign
  • Loading branch information
snewcomer authored Nov 5, 2021
1 parent 09b41bb commit b160113
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 59 deletions.
7 changes: 3 additions & 4 deletions packages/-ember-data/tests/integration/application-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Application from '@ember/application';
import Namespace from '@ember/application/namespace';
import Controller from '@ember/controller';
import { assign } from '@ember/polyfills';
import Service, { inject as service } from '@ember/service';

import { module, test } from 'qunit';
Expand All @@ -26,7 +25,7 @@ module('integration/application - Injecting a Custom Store', function (hooks) {
'controller:baz',
class Controller {
constructor(args) {
assign(this, args);
Object.assign(this, args);
}
@service('store') store;
static create(args) {
Expand Down Expand Up @@ -69,7 +68,7 @@ module('integration/application - Injecting the Default Store', function (hooks)
'controller:baz',
class Controller {
constructor(args) {
assign(this, args);
Object.assign(this, args);
}
@service('store') store;
static create(args) {
Expand Down Expand Up @@ -112,7 +111,7 @@ module('integration/application - Using the store as a service', function (hooks
'controller:baz',
class Controller {
constructor(args) {
assign(this, args);
Object.assign(this, args);
}
@service('store') store;
static create(args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { assign } from '@ember/polyfills';
import { run } from '@ember/runloop';

import { module, test } from 'qunit';
Expand Down Expand Up @@ -52,7 +51,7 @@ module('RecordData Compatibility', function (hooks) {
this.attributes = jsonApiResource.attributes || null;

if (shouldCalculateChanges) {
changedKeys = Object.keys(assign({}, oldAttrs, this.attributes));
changedKeys = Object.keys(Object.assign({}, oldAttrs, this.attributes));
}

return changedKeys || [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { assign } from '@ember/polyfills';
import { run } from '@ember/runloop';

import { module, test } from 'qunit';
Expand All @@ -9,7 +8,7 @@ import Store from '@ember-data/store';

class TestAdapter {
constructor(args) {
assign(this, args);
Object.assign(this, args);
this.didInit();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { assign } from '@ember/polyfills';
import { run } from '@ember/runloop';

import { module, test } from 'qunit';
Expand All @@ -10,7 +9,7 @@ import { deprecatedTest } from '@ember-data/unpublished-test-infra/test-support/

class TestAdapter {
constructor(args) {
assign(this, args);
Object.assign(this, args);
this.didInit();
}

Expand All @@ -23,7 +22,7 @@ class TestAdapter {

class TestSerializer {
constructor(args) {
assign(this, args);
Object.assign(this, args);
this.didInit();
}

Expand Down
3 changes: 1 addition & 2 deletions packages/-ember-data/tests/unit/store/peek-record-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import EmberObject from '@ember/object';
import { assign } from '@ember/polyfills';

import { module, test } from 'qunit';

Expand Down Expand Up @@ -113,7 +112,7 @@ module('unit/store/peekRecord - Store peekRecord', function (hooks) {
peekRecordArgs.lid = recordIdentifierFor(person).lid;
}
if (extra) {
assign(peekRecordArgs, extra);
Object.assign(peekRecordArgs, extra);
}

assert.strictEqual(
Expand Down
7 changes: 3 additions & 4 deletions packages/adapter/addon/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { getOwner } from '@ember/application';
import { assert, deprecate, warn } from '@ember/debug';
import { computed } from '@ember/object';
import { assign } from '@ember/polyfills';
import { join } from '@ember/runloop';
import { DEBUG } from '@glimmer/env';

Expand Down Expand Up @@ -1181,7 +1180,7 @@ class RESTAdapter extends Adapter.extend(BuildURLMixin) {
method: string,
options: JQueryAjaxSettings | RequestInit
): JQueryRequestInit | FetchRequestInit {
let reqOptions: JQueryRequestInit | FetchRequestInit = assign(
let reqOptions: JQueryRequestInit | FetchRequestInit = Object.assign(
{
url,
method,
Expand All @@ -1191,7 +1190,7 @@ class RESTAdapter extends Adapter.extend(BuildURLMixin) {
);

if (this.headers !== undefined) {
reqOptions.headers = assign({}, this.headers, reqOptions.headers);
reqOptions.headers = { ...this.headers, ...reqOptions.headers };
} else if (!options.headers) {
reqOptions.headers = {};
}
Expand All @@ -1209,7 +1208,7 @@ class RESTAdapter extends Adapter.extend(BuildURLMixin) {
// GET requests without a body should not have a content-type header
// and may be unexpected by a server
if (reqOptions.data && reqOptions.type !== 'GET') {
reqOptions = assign(reqOptions, { contentType });
reqOptions = { ...reqOptions, contentType };
}
reqOptions = ajaxOptions(reqOptions, this);
}
Expand Down
4 changes: 1 addition & 3 deletions packages/canary-features/addon/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* globals EmberDataENV */

import { assign } from '@ember/polyfills';

import DEFAULT_FEATURES from './default-features';

type FeatureList = {
Expand All @@ -26,7 +24,7 @@ function featureValue(value: boolean | null): boolean | null {
return value;
}

export const FEATURES: FeatureList = assign({}, DEFAULT_FEATURES, ENV.FEATURES);
export const FEATURES: FeatureList = Object.assign({}, DEFAULT_FEATURES, ENV.FEATURES);
export const SAMPLE_FEATURE_FLAG = featureValue(FEATURES.SAMPLE_FEATURE_FLAG);
export const RECORD_DATA_ERRORS = featureValue(FEATURES.RECORD_DATA_ERRORS);
export const RECORD_DATA_STATE = featureValue(FEATURES.RECORD_DATA_STATE);
Expand Down
9 changes: 4 additions & 5 deletions packages/record-data/addon/-private/record-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @module @ember-data/record-data
*/
import { assert } from '@ember/debug';
import { assign } from '@ember/polyfills';
import { _backburner as emberBackburner } from '@ember/runloop';
import { isEqual } from '@ember/utils';

Expand Down Expand Up @@ -98,7 +97,7 @@ export default class RecordDataDefault implements RelationshipRecordData {
changedKeys = this._changedKeys(data.attributes);
}

assign(this._data, data.attributes);
Object.assign(this._data, data.attributes);
if (this.__attributes) {
// only do if we have attribute changes
this._updateChangedAttributes();
Expand Down Expand Up @@ -241,7 +240,7 @@ export default class RecordDataDefault implements RelationshipRecordData {
let oldData = this._data;
let currentData = this._attributes;
let inFlightData = this._inFlightAttributes;
let newData = assign({}, inFlightData, currentData);
let newData = { ...inFlightData, ...currentData };
let diffData = Object.create(null);
let newDataKeys = Object.keys(newData);

Expand Down Expand Up @@ -305,7 +304,7 @@ export default class RecordDataDefault implements RelationshipRecordData {
}
let changedKeys = this._changedKeys(newCanonicalAttributes);

assign(this._data, this.__inFlightAttributes, newCanonicalAttributes);
Object.assign(this._data, this.__inFlightAttributes, newCanonicalAttributes);

this._inFlightAttributes = null;

Expand Down Expand Up @@ -752,7 +751,7 @@ export default class RecordDataDefault implements RelationshipRecordData {
attrs = this._attributes;
}

original = assign(Object.create(null), this._data, this.__inFlightAttributes);
original = Object.assign(Object.create(null), this._data, this.__inFlightAttributes);

for (i = 0; i < length; i++) {
key = keys[i];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { assign } from '@ember/polyfills';
import settled from '@ember/test-helpers/settled';

import { module, test as runTest } from 'qunit';
Expand Down Expand Up @@ -129,19 +128,19 @@ module('Integration | Graph | Edge Removal', function (hooks) {

TestScenarios.forEach(unpersistedDeletionTest);
TestScenarios.forEach((testConfig) => {
const config = assign({}, testConfig, { name: `[Newly Created] ${testConfig.name}`, useCreate: true });
const config = Object.assign({}, testConfig, { name: `[Newly Created] ${testConfig.name}`, useCreate: true });
unpersistedDeletionTest(config);
});
TestScenarios.forEach((testConfig) => {
const config = assign({}, testConfig, { name: `[LOCAL STATE] ${testConfig.name}`, dirtyLocal: true });
const config = Object.assign({}, testConfig, { name: `[LOCAL STATE] ${testConfig.name}`, dirtyLocal: true });
unpersistedDeletionTest(config);
});
});

module('Unload of a Record does not remove it from the graph', function () {
function unloadTest(_config: TestConfig) {
test(_config.name, async function (this: Context, assert) {
const config = assign({}, _config, { isUnloadAsDelete: true });
const config = Object.assign({}, _config, { isUnloadAsDelete: true });
const testState = await setInitialState(this, config, assert);
const { john } = testState;

Expand Down Expand Up @@ -185,11 +184,11 @@ module('Integration | Graph | Edge Removal', function (hooks) {

TestScenarios.forEach(unloadTest);
TestScenarios.forEach((testConfig) => {
const config = assign({}, testConfig, { name: `[Newly Created] ${testConfig.name}`, useCreate: true });
const config = Object.assign({}, testConfig, { name: `[Newly Created] ${testConfig.name}`, useCreate: true });
unloadTest(config);
});
TestScenarios.forEach((testConfig) => {
const config = assign({}, testConfig, { name: `[LOCAL STATE] ${testConfig.name}`, dirtyLocal: true });
const config = Object.assign({}, testConfig, { name: `[LOCAL STATE] ${testConfig.name}`, dirtyLocal: true });
unloadTest(config);
});
});
Expand Down Expand Up @@ -231,11 +230,11 @@ module('Integration | Graph | Edge Removal', function (hooks) {

TestScenarios.forEach(persistedDeletionTest);
TestScenarios.forEach((testConfig) => {
const config = assign({}, testConfig, { name: `[Newly Created] ${testConfig.name}`, useCreate: true });
const config = Object.assign({}, testConfig, { name: `[Newly Created] ${testConfig.name}`, useCreate: true });
persistedDeletionTest(config);
});
TestScenarios.forEach((testConfig) => {
const config = assign({}, testConfig, { name: `[LOCAL STATE] ${testConfig.name}`, dirtyLocal: true });
const config = Object.assign({}, testConfig, { name: `[LOCAL STATE] ${testConfig.name}`, dirtyLocal: true });
persistedDeletionTest(config);
});
});
Expand All @@ -259,11 +258,11 @@ module('Integration | Graph | Edge Removal', function (hooks) {

TestScenarios.forEach(persistedDeletionUnloadedTest);
TestScenarios.forEach((testConfig) => {
const config = assign({}, testConfig, { name: `[Newly Created] ${testConfig.name}`, useCreate: true });
const config = Object.assign({}, testConfig, { name: `[Newly Created] ${testConfig.name}`, useCreate: true });
persistedDeletionUnloadedTest(config);
});
TestScenarios.forEach((testConfig) => {
const config = assign({}, testConfig, { name: `[LOCAL STATE] ${testConfig.name}`, dirtyLocal: true });
const config = Object.assign({}, testConfig, { name: `[LOCAL STATE] ${testConfig.name}`, dirtyLocal: true });
persistedDeletionUnloadedTest(config);
});
});
Expand Down
3 changes: 1 addition & 2 deletions packages/serializer/addon/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { getOwner } from '@ember/application';
import { assert, warn } from '@ember/debug';
import { get } from '@ember/object';
import { assign } from '@ember/polyfills';
import { isNone, typeOf } from '@ember/utils';

import Serializer from '@ember-data/serializer';
Expand Down Expand Up @@ -1155,7 +1154,7 @@ const JSONSerializer = Serializer.extend({
@param {Object} options
*/
serializeIntoHash(hash, typeClass, snapshot, options) {
assign(hash, this.serialize(snapshot, options));
Object.assign(hash, this.serialize(snapshot, options));
},

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/store/addon/-private/identifiers/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
@module @ember-data/store
*/
import { assert, warn } from '@ember/debug';
import { assign } from '@ember/polyfills';
import { DEBUG } from '@glimmer/env';

import coerceId from '../system/coerce-id';
Expand Down Expand Up @@ -372,7 +371,7 @@ export class IdentifierCache {
// If the incoming type does not match the identifier type, we need to create an identifier for the incoming
// data so we can merge the incoming data with the existing identifier, see #7325 and #7363
if ('type' in data && data.type && identifier.type !== normalizeModelName(data.type)) {
let incomingDataResource = assign({}, data);
let incomingDataResource = { ...data };
// Need to strip the lid from the incomingData in order force a new identifier creation
delete incomingDataResource.lid;
existingIdentifier = this.getOrCreateRecordIdentifier(incomingDataResource);
Expand Down
3 changes: 1 addition & 2 deletions packages/store/addon/-private/system/core-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { getOwner } from '@ember/application';
import { A } from '@ember/array';
import { assert, deprecate, inspect, warn } from '@ember/debug';
import { computed, defineProperty, get, set } from '@ember/object';
import { assign } from '@ember/polyfills';
import { _backburner as emberBackburner } from '@ember/runloop';
import type { Backburner } from '@ember/runloop/-private/backburner';
import Service from '@ember/service';
Expand Down Expand Up @@ -646,7 +645,7 @@ abstract class CoreStore extends Service {
return emberBackburner.join(() => {
return this._backburner.join(() => {
let normalizedModelName = normalizeModelName(modelName);
let properties = assign({}, inputProperties);
let properties = { ...inputProperties };

// If the passed properties do not include a primary key,
// give the adapter an opportunity to generate one. Typically,
Expand Down
3 changes: 1 addition & 2 deletions packages/store/addon/-private/system/ds-model-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { getOwner, setOwner } from '@ember/application';
import { assert, deprecate } from '@ember/debug';
import EmberError from '@ember/error';
import { get } from '@ember/object';
import { assign } from '@ember/polyfills';
import { isPresent } from '@ember/utils';
import { DEBUG } from '@glimmer/env';

Expand Down Expand Up @@ -40,7 +39,7 @@ class Store extends CoreStore {
_internalModel: internalModel,
container: null,
};
assign(createOptions, createRecordArgs);
Object.assign(createOptions, createRecordArgs);

// ensure that `getOwner(this)` works inside a model instance
setOwner(createOptions, getOwner(this));
Expand Down
3 changes: 1 addition & 2 deletions packages/store/addon/-private/system/model/internal-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { A, default as EmberArray } from '@ember/array';
import { assert, inspect } from '@ember/debug';
import EmberError from '@ember/error';
import { get, set } from '@ember/object';
import { assign } from '@ember/polyfills';
import { _backburner as emberBackburner, cancel, run } from '@ember/runloop';
import { DEBUG } from '@glimmer/env';

Expand Down Expand Up @@ -354,7 +353,7 @@ export default class InternalModel {
}

let additionalCreateOptions = this._recordData._initRecordCreateOptions(properties);
assign(createOptions, additionalCreateOptions);
Object.assign(createOptions, additionalCreateOptions);

// ensure that `getOwner(this)` works inside a model instance
setOwner(createOptions, getOwner(store));
Expand Down
5 changes: 2 additions & 3 deletions packages/store/addon/-private/system/record-array-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import { A } from '@ember/array';
import { assert } from '@ember/debug';
import { get, set } from '@ember/object';
import { assign } from '@ember/polyfills';
import { _backburner as emberBackburner } from '@ember/runloop';

import { REMOVE_RECORD_ARRAY_MANAGER_LEGACY_COMPAT } from '@ember-data/canary-features';
Expand Down Expand Up @@ -281,8 +280,8 @@ class RecordArrayManager {
manager: this,
isLoaded: true,
isUpdating: false,
meta: assign({}, payload.meta),
links: assign({}, payload.links),
meta: { ...payload.meta },
links: { ...payload.links },
});

this._associateWithRecordArray(identifiers, array);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { A } from '@ember/array';
import { get } from '@ember/object';
import { assign } from '@ember/polyfills';
import { once } from '@ember/runloop';
import { DEBUG } from '@glimmer/env';

Expand Down Expand Up @@ -86,8 +85,8 @@ let AdapterPopulatedRecordArray = RecordArray.extend({
this.setProperties({
isLoaded: true,
isUpdating: false,
meta: assign({}, payload.meta),
links: assign({}, payload.links),
meta: { ...payload.meta },
links: { ...payload.links },
});

this.manager._associateWithRecordArray(identifiersOrInternalModels, this);
Expand Down
Loading

0 comments on commit b160113

Please sign in to comment.