diff --git a/packages/@ember/-internals/runtime/index.js b/packages/@ember/-internals/runtime/index.js index 6558895952b..7c3e2d5ab93 100644 --- a/packages/@ember/-internals/runtime/index.js +++ b/packages/@ember/-internals/runtime/index.js @@ -1,7 +1,6 @@ export { default as Object, FrameworkObject } from './lib/system/object'; export { default as RegistryProxyMixin } from './lib/mixins/registry_proxy'; export { default as ContainerProxyMixin } from './lib/mixins/container_proxy'; -export { default as copy } from './lib/copy'; export { default as compare } from './lib/compare'; export { default as isEqual } from './lib/is-equal'; export { @@ -19,7 +18,6 @@ export { default as ArrayProxy } from './lib/system/array_proxy'; export { default as ObjectProxy } from './lib/system/object_proxy'; export { default as CoreObject } from './lib/system/core_object'; export { default as ActionHandler } from './lib/mixins/action_handler'; -export { default as Copyable } from './lib/mixins/copyable'; export { default as Enumerable } from './lib/mixins/enumerable'; export { default as _ProxyMixin, contentFor as _contentFor } from './lib/mixins/-proxy'; export { default as Observable } from './lib/mixins/observable'; diff --git a/packages/@ember/-internals/runtime/lib/copy.js b/packages/@ember/-internals/runtime/lib/copy.js deleted file mode 100644 index b3416485569..00000000000 --- a/packages/@ember/-internals/runtime/lib/copy.js +++ /dev/null @@ -1,120 +0,0 @@ -import { assert, deprecate } from '@ember/debug'; -import EmberObject from './system/object'; -import Copyable from './mixins/copyable'; - -/** - @module @ember/object -*/ -function _copy(obj, deep, seen, copies) { - // primitive data types are immutable, just return them. - if (typeof obj !== 'object' || obj === null) { - return obj; - } - - let ret, loc; - - // avoid cyclical loops - if (deep && (loc = seen.indexOf(obj)) >= 0) { - return copies[loc]; - } - - if (deep) { - seen.push(obj); - } - - // IMPORTANT: this specific test will detect a native array only. Any other - // object will need to implement Copyable. - if (Array.isArray(obj)) { - ret = obj.slice(); - - if (deep) { - copies.push(ret); - loc = ret.length; - - while (--loc >= 0) { - ret[loc] = _copy(ret[loc], deep, seen, copies); - } - } - } else if (Copyable.detect(obj)) { - ret = obj.copy(deep, seen, copies); - if (deep) { - copies.push(ret); - } - } else if (obj instanceof Date) { - ret = new Date(obj.getTime()); - if (deep) { - copies.push(ret); - } - } else { - assert( - 'Cannot clone an EmberObject that does not implement Copyable', - !(obj instanceof EmberObject) || Copyable.detect(obj) - ); - - ret = {}; - if (deep) { - copies.push(ret); - } - - let key; - for (key in obj) { - // support Null prototype - if (!Object.prototype.hasOwnProperty.call(obj, key)) { - continue; - } - - // Prevents browsers that don't respect non-enumerability from - // copying internal Ember properties - if (key.substring(0, 2) === '__') { - continue; - } - - ret[key] = deep ? _copy(obj[key], deep, seen, copies) : obj[key]; - } - } - - return ret; -} - -/** - Creates a shallow copy of the passed object. A deep copy of the object is - returned if the optional `deep` argument is `true`. - - If the passed object implements the `Copyable` interface, then this - function will delegate to the object's `copy()` method and return the - result. See `Copyable` for further details. - - For primitive values (which are immutable in JavaScript), the passed object - is simply returned. - - @method copy - @deprecated Use 'ember-copy' addon instead - @static - @for @ember/object/internals - @param {Object} obj The object to clone - @param {Boolean} [deep=false] If true, a deep copy of the object is made. - @return {Object} The copied object - @public -*/ -export default function copy(obj, deep) { - deprecate('Use ember-copy addon instead of copy method and Copyable mixin.', false, { - id: 'ember-runtime.deprecate-copy-copyable', - until: '4.0.0', - url: 'https://deprecations.emberjs.com/v3.x/#toc_ember-runtime-deprecate-copy-copyable', - for: 'ember-source', - since: { - enabled: '3.3.0', - }, - }); - - // fast paths - if ('object' !== typeof obj || obj === null) { - return obj; // can't copy primitives - } - - if (!Array.isArray(obj) && Copyable.detect(obj)) { - return obj.copy(deep); - } - - return _copy(obj, deep, deep ? [] : null, deep ? [] : null); -} diff --git a/packages/@ember/-internals/runtime/lib/mixins/copyable.js b/packages/@ember/-internals/runtime/lib/mixins/copyable.js deleted file mode 100644 index 7a09d373f52..00000000000 --- a/packages/@ember/-internals/runtime/lib/mixins/copyable.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -@module ember -*/ - -import { Mixin } from '@ember/-internals/metal'; - -/** - Implements some standard methods for copying an object. Add this mixin to - any object you create that can create a copy of itself. This mixin is - added automatically to the built-in array. - - You should generally implement the `copy()` method to return a copy of the - receiver. - - @class Copyable - @namespace Ember - @since Ember 0.9 - @deprecated Use 'ember-copy' addon instead - @private -*/ -export default Mixin.create({ - /** - __Required.__ You must implement this method to apply this mixin. - - Override to return a copy of the receiver. Default implementation raises - an exception. - - @method copy - @param {Boolean} deep if `true`, a deep copy of the object should be made - @return {Object} copy of receiver - @private - */ - copy: null, -}); diff --git a/packages/@ember/-internals/runtime/tests/copyable-array/copy-test.js b/packages/@ember/-internals/runtime/tests/copyable-array/copy-test.js deleted file mode 100644 index 999cacb34bb..00000000000 --- a/packages/@ember/-internals/runtime/tests/copyable-array/copy-test.js +++ /dev/null @@ -1,12 +0,0 @@ -import { AbstractTestCase } from 'internal-test-helpers'; -import { runArrayTests } from '../helpers/array'; - -class CopyTest extends AbstractTestCase { - '@test should return an equivalent copy'() { - let obj = this.newObject(); - let copy = obj.copy(); - this.assert.ok(this.isEqual(obj, copy), 'old object and new object should be equivalent'); - } -} - -runArrayTests('copy', CopyTest, 'CopyableNativeArray', 'CopyableArray'); diff --git a/packages/@ember/-internals/runtime/tests/core/copy_test.js b/packages/@ember/-internals/runtime/tests/core/copy_test.js deleted file mode 100644 index 063d83ca44a..00000000000 --- a/packages/@ember/-internals/runtime/tests/core/copy_test.js +++ /dev/null @@ -1,64 +0,0 @@ -import copy from '../../lib/copy'; -import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; - -moduleFor( - 'Ember Copy Method', - class extends AbstractTestCase { - ['@test Ember.copy null'](assert) { - let obj = { field: null }; - let copied = null; - expectDeprecation(() => { - copied = copy(obj, true); - }, 'Use ember-copy addon instead of copy method and Copyable mixin.'); - assert.equal(copied.field, null, 'null should still be null'); - } - - ['@test Ember.copy date'](assert) { - let date = new Date(2014, 7, 22); - let dateCopy = null; - expectDeprecation(() => { - dateCopy = copy(date); - }, 'Use ember-copy addon instead of copy method and Copyable mixin.'); - assert.equal(date.getTime(), dateCopy.getTime(), 'dates should be equivalent'); - } - - ['@test Ember.copy null prototype object'](assert) { - let obj = Object.create(null); - - obj.foo = 'bar'; - let copied = null; - expectDeprecation(() => { - copied = copy(obj); - }, 'Use ember-copy addon instead of copy method and Copyable mixin.'); - - assert.equal(copied.foo, 'bar', 'bar should still be bar'); - } - - ['@test Ember.copy Array'](assert) { - let array = [1, null, new Date(2015, 9, 9), 'four']; - let arrayCopy = null; - expectDeprecation(() => { - arrayCopy = copy(array); - }, 'Use ember-copy addon instead of copy method and Copyable mixin.'); - - assert.deepEqual(array, arrayCopy, 'array content cloned successfully in new array'); - } - - ['@test Ember.copy cycle detection'](assert) { - let obj = { - foo: { - bar: 'bar', - }, - }; - obj.foo.foo = obj.foo; - let cycleCopy = null; - expectDeprecation(() => { - cycleCopy = copy(obj, true); - }, 'Use ember-copy addon instead of copy method and Copyable mixin.'); - - assert.equal(cycleCopy.foo.bar, 'bar'); - assert.notEqual(cycleCopy.foo.foo, obj.foo.foo); - assert.strictEqual(cycleCopy.foo.foo, cycleCopy.foo.foo); - } - } -); diff --git a/packages/@ember/-internals/runtime/tests/helpers/array.js b/packages/@ember/-internals/runtime/tests/helpers/array.js index 3efb0459c5f..0f5f5008d38 100644 --- a/packages/@ember/-internals/runtime/tests/helpers/array.js +++ b/packages/@ember/-internals/runtime/tests/helpers/array.js @@ -3,7 +3,6 @@ import EmberArray, { A as emberA, MutableArray } from '../../lib/mixins/array'; import { generateGuid, guidFor } from '@ember/-internals/utils'; import { get, - set, computed, addArrayObserver, removeArrayObserver, @@ -11,7 +10,6 @@ import { arrayContentDidChange, } from '@ember/-internals/metal'; import EmberObject from '../../lib/system/object'; -import Copyable from '../../lib/mixins/copyable'; import { moduleFor } from 'internal-test-helpers'; export function newFixture(cnt) { @@ -147,42 +145,6 @@ class NativeArrayHelpers extends AbstractArrayHelper { } } -class CopyableNativeArray extends AbstractArrayHelper { - newObject() { - return emberA([generateGuid()]); - } - - isEqual(a, b) { - if (!(a instanceof Array)) { - return false; - } - - if (!(b instanceof Array)) { - return false; - } - - if (a.length !== b.length) { - return false; - } - - return a[0] === b[0]; - } -} - -class CopyableArray extends AbstractArrayHelper { - newObject() { - return CopyableObject.create(); - } - - isEqual(a, b) { - if (!(a instanceof CopyableObject) || !(b instanceof CopyableObject)) { - return false; - } - - return get(a, 'id') === get(b, 'id'); - } -} - class ArrayProxyHelpers extends AbstractArrayHelper { newObject(ary) { return ArrayProxy.create({ content: emberA(super.newObject(ary)) }); @@ -271,21 +233,6 @@ const TestMutableArray = EmberObject.extend(MutableArray, { }, }); -const CopyableObject = EmberObject.extend(Copyable, { - id: null, - - init() { - this._super(...arguments); - set(this, 'id', generateGuid()); - }, - - copy() { - let ret = CopyableObject.create(); - set(ret, 'id', get(this, 'id')); - return ret; - }, -}); - class MutableArrayHelpers extends NativeArrayHelpers { newObject(ary) { return TestMutableArray.create(super.newObject(ary)); @@ -316,15 +263,11 @@ export function runArrayTests(name, Tests, ...types) { case 'MutableArray': moduleFor(`MutableArray: ${name}`, Tests, MutableArrayHelpers); break; - case 'CopyableArray': - moduleFor(`CopyableArray: ${name}`, Tests, CopyableArray); - break; - case 'CopyableNativeArray': - moduleFor(`CopyableNativeArray: ${name}`, Tests, CopyableNativeArray); - break; case 'NativeArray': moduleFor(`NativeArray: ${name}`, Tests, NativeArrayHelpers); break; + default: + throw new Error(`runArrayTests passed unexpected type ${type}`); } }); } else { diff --git a/packages/@ember/object/internals.js b/packages/@ember/object/internals.js index 1c709857059..8093f908605 100644 --- a/packages/@ember/object/internals.js +++ b/packages/@ember/object/internals.js @@ -1,3 +1,2 @@ export { getCachedValueFor as cacheFor } from '@ember/-internals/metal'; -export { copy } from '@ember/-internals/runtime'; export { guidFor } from '@ember/-internals/utils'; diff --git a/packages/ember/index.js b/packages/ember/index.js index b8f3b854bcd..7661239a5b1 100644 --- a/packages/ember/index.js +++ b/packages/ember/index.js @@ -41,10 +41,8 @@ import { RegistryProxyMixin, ContainerProxyMixin, compare, - copy, isEqual, Array as EmberArray, - Copyable, MutableEnumerable, MutableArray, TargetActionSupport, @@ -397,7 +395,6 @@ Ember.Object = EmberObject; Ember._RegistryProxyMixin = RegistryProxyMixin; Ember._ContainerProxyMixin = ContainerProxyMixin; Ember.compare = compare; -Ember.copy = copy; Ember.isEqual = isEqual; /** @@ -430,7 +427,6 @@ Ember.ObjectProxy = ObjectProxy; Ember.ActionHandler = ActionHandler; Ember.CoreObject = CoreObject; Ember.NativeArray = NativeArray; -Ember.Copyable = Copyable; Ember.MutableEnumerable = MutableEnumerable; Ember.MutableArray = MutableArray; Ember.Evented = Evented; diff --git a/packages/ember/tests/reexports_test.js b/packages/ember/tests/reexports_test.js index 4bccf517f6b..f834dded2f1 100644 --- a/packages/ember/tests/reexports_test.js +++ b/packages/ember/tests/reexports_test.js @@ -351,7 +351,6 @@ let allExports = [ // @ember/object/internals ['cacheFor', '@ember/object/internals', 'cacheFor'], - ['copy', '@ember/object/internals', 'copy'], ['guidFor', '@ember/object/internals', 'guidFor'], // @ember/object/mixin @@ -546,7 +545,6 @@ let allExports = [ ['Comparable', '@ember/-internals/runtime'], ['ActionHandler', '@ember/-internals/runtime'], ['NativeArray', '@ember/-internals/runtime'], - ['Copyable', '@ember/-internals/runtime'], ['MutableEnumerable', '@ember/-internals/runtime'], EMBER_MODERNIZED_BUILT_IN_COMPONENTS ? null