Skip to content

Commit

Permalink
Merge pull request #19649 from nlfurniss/deprecate-ember-assign
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic authored Aug 1, 2021
2 parents 015bd42 + ca106b1 commit 560751f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 40 deletions.
7 changes: 3 additions & 4 deletions packages/@ember/-internals/routing/lib/system/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Controller from '@ember/controller';
import { assert, deprecate, info } from '@ember/debug';
import { APP_CTRL_ROUTER_PROPS, ROUTER_EVENTS } from '@ember/deprecated-features';
import EmberError from '@ember/error';
import { assign } from '@ember/polyfills';
import { cancel, once, run, scheduleOnce } from '@ember/runloop';
import { DEBUG } from '@glimmer/env';
import EmberLocation, { EmberLocation as IEmberLocation } from '../location/api';
Expand Down Expand Up @@ -1018,7 +1017,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented {

this._processActiveTransitionQueryParams(targetRouteName, models, queryParams, _queryParams);

assign(queryParams, _queryParams);
Object.assign(queryParams, _queryParams);
this._prepareQueryParams(
targetRouteName,
models,
Expand Down Expand Up @@ -1059,7 +1058,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented {
// from the active transition.
this._fullyScopeQueryParams(targetRouteName, models, _queryParams);
this._fullyScopeQueryParams(targetRouteName, models, unchangedQPs);
assign(queryParams, unchangedQPs);
Object.assign(queryParams, unchangedQPs);
}

/**
Expand Down Expand Up @@ -1156,7 +1155,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented {
qps.push(qp);
}

assign(map, qpMeta.map);
Object.assign(map, qpMeta.map);
}

let finalQPMeta = { qps, map };
Expand Down
1 change: 1 addition & 0 deletions packages/@ember/deprecated-features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export const JQUERY_INTEGRATION = !!'3.9.0';
export const APP_CTRL_ROUTER_PROPS = !!'3.10.0-beta.1';
export const MOUSE_ENTER_LEAVE_MOVE_EVENTS = !!'3.13.0-beta.1';
export const PARTIALS = !!'3.15.0-beta.1';
export const ASSIGN = !!'4.0.0-beta.1';
3 changes: 1 addition & 2 deletions packages/@ember/polyfills/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Export `assignPolyfill` for testing
export { default as assign, assign as assignPolyfill } from './lib/assign';
export { assign } from './lib/assign';

export const hasPropertyAccessors = true;
39 changes: 17 additions & 22 deletions packages/@ember/polyfills/lib/assign.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { deprecate } from '@ember/debug';

/**
@module @ember/polyfills
*/

export function assign<T, U>(target: T, source: U): T & U;
export function assign<T, U, V>(target: T, source1: U, source2: V): T & U & V;
export function assign<T, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
export function assign(target: object, ...sources: any[]): any;
export function assign(target: object, ...sources: object[]): object;
/**
Copy properties from a source object to a target object. Source arguments remain unchanged.
Expand All @@ -27,27 +29,20 @@ export function assign(target: object, ...sources: any[]): any;
@public
@static
*/
export function assign(target: object) {
for (let i = 1; i < arguments.length; i++) {
let arg = arguments[i];
if (!arg) {
continue;
export function assign(target: object): object {
deprecate(
'Use of `assign` has been deprecated. Please use `Object.assign` or the spread operator instead.',
false,
{
id: 'ember-polyfills.deprecate-assign',
until: '5.0.0',
url: 'https://deprecations.emberjs.com/v4.x/#toc_ember-polyfills-deprecate-assign',
for: 'ember-source',
since: {
enabled: '4.0.0',
},
}
);

let updates = Object.keys(arg);

for (let i = 0; i < updates.length; i++) {
let prop = updates[i];
target[prop] = arg[prop];
}
}

return target;
return Object.assign(target, ...arguments);
}

// Note: We use the bracket notation so
// that the babel plugin does not
// transform it.
// https://www.npmjs.com/package/babel-plugin-transform-object-assign
const { assign: _assign } = Object;
export default (_assign || assign) as typeof assign;
15 changes: 4 additions & 11 deletions packages/@ember/polyfills/tests/assign_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assignPolyfill, assign } from '..';
import { assign as assignPolyfill } from '..';
import { moduleFor, AbstractTestCase as TestCase } from 'internal-test-helpers';

class AssignTests extends TestCase {
Expand Down Expand Up @@ -49,16 +49,9 @@ moduleFor(
'Ember.assign (polyfill)',
class extends AssignTests {
assign() {
return assignPolyfill(...arguments);
}
}
);

moduleFor(
'Ember.assign (maybe not-polyfill ;) )',
class extends AssignTests {
assign() {
return assign(...arguments);
return expectDeprecation(() => {
assignPolyfill(...arguments);
}, 'Use of `assign` has been deprecated. Please use `Object.assign` or the spread operator instead.');
}
}
);
2 changes: 1 addition & 1 deletion packages/ember/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Ember.get = metal.get;
Ember._getPath = metal._getPath;
Ember.set = metal.set;
Ember.trySet = metal.trySet;
Ember.FEATURES = assign({ isEnabled }, FEATURES);
Ember.FEATURES = Object.assign({ isEnabled }, FEATURES);
Ember._Cache = utils.Cache;
Ember.on = metal.on;
Ember.addListener = metal.addListener;
Expand Down

0 comments on commit 560751f

Please sign in to comment.