From c661a45df046740aed9bcfbda576fb05532022f4 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 30 Nov 2017 12:11:34 -0500 Subject: [PATCH] Remove Map/MapWithDefault/OrderedSet implementations/aliases/remnants --- .../-internals/metal/tests/is_empty_test.js | 28 - packages/@ember/deprecated-features/index.ts | 2 - packages/@ember/map/index.js | 218 ------- packages/@ember/map/lib/ordered-set.js | 186 ------ packages/@ember/map/lib/utils.js | 29 - packages/@ember/map/tests/map_test.js | 577 ------------------ packages/@ember/map/with-default.js | 87 --- packages/ember/index.js | 9 - packages/ember/tests/reexports_test.js | 3 - tests/docs/expected.js | 2 - 10 files changed, 1141 deletions(-) delete mode 100644 packages/@ember/map/index.js delete mode 100644 packages/@ember/map/lib/ordered-set.js delete mode 100644 packages/@ember/map/lib/utils.js delete mode 100644 packages/@ember/map/tests/map_test.js delete mode 100644 packages/@ember/map/with-default.js diff --git a/packages/@ember/-internals/metal/tests/is_empty_test.js b/packages/@ember/-internals/metal/tests/is_empty_test.js index ccb9b8c4936..b4c01b89ace 100644 --- a/packages/@ember/-internals/metal/tests/is_empty_test.js +++ b/packages/@ember/-internals/metal/tests/is_empty_test.js @@ -1,6 +1,4 @@ import { isEmpty } from '..'; -import Map from '@ember/map'; -import OrderedSet from '@ember/map/lib/ordered-set'; import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; moduleFor( @@ -25,31 +23,5 @@ moduleFor( assert.equal(false, isEmpty({}), 'for an empty Object'); assert.equal(true, isEmpty(object), "for an Object that has zero 'length'"); } - - ['@test isEmpty Map'](assert) { - expectDeprecation( - () => { - let map = new Map(); - assert.equal(true, isEmpty(map), 'Empty map is empty'); - map.set('foo', 'bar'); - assert.equal(false, isEmpty(map), 'Map is not empty'); - }, - 'Use of @ember/Map is deprecated. Please use native `Map` instead', - { id: 'ember-map-deprecation', until: '3.5.0' } - ); - } - - ['@test isEmpty Ember.OrderedSet'](assert) { - expectDeprecation( - () => { - let orderedSet = new OrderedSet(); - assert.equal(true, isEmpty(orderedSet), 'Empty ordered set is empty'); - orderedSet.add('foo'); - assert.equal(false, isEmpty(orderedSet), 'Ordered set is not empty'); - }, - 'Use of @ember/OrderedSet is deprecated. Please use native `Map` instead', - { id: 'ember-map-deprecation', until: '3.5.0' } - ); - } } ); diff --git a/packages/@ember/deprecated-features/index.ts b/packages/@ember/deprecated-features/index.ts index decb11e5c12..11c97ee591a 100644 --- a/packages/@ember/deprecated-features/index.ts +++ b/packages/@ember/deprecated-features/index.ts @@ -3,8 +3,6 @@ export const EMBER_EXTEND_PROTOTYPES = !!'3.2.0-beta.5'; export const RUN_SYNC = !!'3.0.0-beta.4'; export const LOGGER = !!'3.2.0-beta.1'; export const ARRAY_AT_EACH = !!'3.1.0-beta.1'; -export const MAP = !!'3.3.0-beta.1'; -export const ORDERED_SET = !!'3.3.0-beta.1'; export const MERGE = !!'3.6.0-beta.1'; export const HANDLER_INFOS = !!'3.9.0'; export const ROUTER_EVENTS = !!'3.9.0'; diff --git a/packages/@ember/map/index.js b/packages/@ember/map/index.js deleted file mode 100644 index ad1558e33ce..00000000000 --- a/packages/@ember/map/index.js +++ /dev/null @@ -1,218 +0,0 @@ -import { assert, deprecate } from '@ember/debug'; -import { guidFor } from '@ember/-internals/utils'; -import OrderedSet from './lib/ordered-set'; -import { copyMap } from './lib/utils'; -import { MAP } from '@ember/deprecated-features'; - -/** -@module @ember/map -@private -*/ - -let Map; - -if (MAP) { - /* - JavaScript (before ES6) does not have a Map implementation. Objects, - which are often used as dictionaries, may only have Strings as keys. - - Because Ember has a way to get a unique identifier for every object - via `guidFor`, we can implement a performant Map with arbitrary - keys. Because it is commonly used in low-level bookkeeping, Map is - implemented as a pure JavaScript object for performance. - - This implementation follows the current iteration of the ES6 proposal for - maps (http://wiki.ecmascript.org/doku.php?id=harmony:simple_maps_and_sets), - with one exception: as we do not have the luxury of in-VM iteration, we implement a - forEach method for iteration. - - Map is mocked out to look like an Ember object, so you can do - `EmberMap.create()` for symmetry with other Ember classes. -*/ - - /** - A Map stores values indexed by keys. Unlike JavaScript's - default Objects, the keys of a Map can be any JavaScript - object. - - Internally, a Map has two data structures: - - 1. `keys`: an OrderedSet of all of the existing keys - 2. `values`: a JavaScript Object indexed by the `guidFor(key)` - - When a key/value pair is added for the first time, we - add the key to the `keys` OrderedSet, and create or - replace an entry in `values`. When an entry is deleted, - we delete its entry in `keys` and `values`. - - @class Map - @private - @constructor - @deprecated use native `Map` instead. -*/ - Map = class Map { - constructor() { - deprecate('Use of @ember/Map is deprecated. Please use native `Map` instead', false, { - id: 'ember-map-deprecation', - until: '3.5.0', - }); - - this._keys = new OrderedSet(); - this._values = Object.create(null); - this.size = 0; - } - - /** - @method create - @static - @private - */ - static create() { - let Constructor = this; - return new Constructor(); - } - - /** - Retrieve the value associated with a given key. - - @method get - @param {*} key - @return {*} the value associated with the key, or `undefined` - @private - */ - get(key) { - if (this.size === 0) { - return; - } - - let values = this._values; - let guid = guidFor(key); - - return values[guid]; - } - - /** - Adds a value to the map. If a value for the given key has already been - provided, the new value will replace the old value. - - @method set - @param {*} key - @param {*} value - @return {Map} - @private - */ - set(key, value) { - let keys = this._keys; - let values = this._values; - let guid = guidFor(key); - - // ensure we don't store -0 - let k = key === -0 ? 0 : key; // eslint-disable-line no-compare-neg-zero - - keys.add(k, guid); - - values[guid] = value; - - this.size = keys.size; - - return this; - } - - /** - Removes a value from the map for an associated key. - - @since 1.8.0 - @method delete - @param {*} key - @return {Boolean} true if an item was removed, false otherwise - @private - */ - delete(key) { - if (this.size === 0) { - return false; - } - // don't use ES6 "delete" because it will be annoying - // to use in browsers that are not ES6 friendly; - let keys = this._keys; - let values = this._values; - let guid = guidFor(key); - - if (keys.delete(key, guid)) { - delete values[guid]; - this.size = keys.size; - return true; - } else { - return false; - } - } - - /** - Check whether a key is present. - - @method has - @param {*} key - @return {Boolean} true if the item was present, false otherwise - @private - */ - has(key) { - return this._keys.has(key); - } - - /** - Iterate over all the keys and values. Calls the function once - for each key, passing in value, key, and the map being iterated over, - in that order. - - The keys are guaranteed to be iterated over in insertion order. - - @method forEach - @param {Function} callback - @param {*} self if passed, the `this` value inside the - callback. By default, `this` is the map. - @private - */ - forEach(callback /*, ...thisArg*/) { - assert( - `${Object.prototype.toString.call(callback)} is not a function`, - typeof callback === 'function' - ); - - if (this.size === 0) { - return; - } - - let map = this; - let cb, thisArg; - - if (arguments.length === 2) { - thisArg = arguments[1]; - cb = key => callback.call(thisArg, map.get(key), key, map); - } else { - cb = key => callback(map.get(key), key, map); - } - - this._keys.forEach(cb); - } - - /** - @method clear - @private - */ - clear() { - this._keys.clear(); - this._values = Object.create(null); - this.size = 0; - } - - /** - @method copy - @return {Map} - @private - */ - copy() { - return copyMap(this, new Map()); - } - }; -} - -export default Map; diff --git a/packages/@ember/map/lib/ordered-set.js b/packages/@ember/map/lib/ordered-set.js deleted file mode 100644 index dc6be9c8dcd..00000000000 --- a/packages/@ember/map/lib/ordered-set.js +++ /dev/null @@ -1,186 +0,0 @@ -import { assert, deprecate } from '@ember/debug'; -import { guidFor } from '@ember/-internals/utils'; -import { copyNull } from './utils'; -import { ORDERED_SET } from '@ember/deprecated-features'; - -/** - This class is used internally by Ember and Ember Data. - Please do not use it at this time. We plan to clean it up - and add many tests soon. - - @class OrderedSet - @namespace Ember - @constructor - @private - @deprecated -*/ -let __OrderedSet__, OrderedSet; -/** - * This is exported so it can be used by the OrderedSet library. - * This is private do not use it. - @private - */ - -if (ORDERED_SET) { - __OrderedSet__ = class __OrderedSet__ { - constructor() { - this.clear(); - } - /** - @method create - @static - @return {Ember.OrderedSet} - @private - */ - static create() { - let Constructor = this; - return new Constructor(); - } - - /** - @method clear - @private - */ - clear() { - this.presenceSet = Object.create(null); - this.list = []; - this.size = 0; - } - - /** - @method add - @param obj - @param guid (optional, and for internal use) - @return {Ember.OrderedSet} - @private - */ - add(obj, _guid) { - let guid = _guid || guidFor(obj); - let presenceSet = this.presenceSet; - let list = this.list; - - if (presenceSet[guid] !== true) { - presenceSet[guid] = true; - this.size = list.push(obj); - } - - return this; - } - - /** - @since 1.8.0 - @method delete - @param obj - @param _guid (optional and for internal use only) - @return {Boolean} - @private - */ - delete(obj, _guid) { - let guid = _guid || guidFor(obj); - let presenceSet = this.presenceSet; - let list = this.list; - - if (presenceSet[guid] === true) { - delete presenceSet[guid]; - let index = list.indexOf(obj); - if (index > -1) { - list.splice(index, 1); - } - this.size = list.length; - return true; - } else { - return false; - } - } - - /** - @method isEmpty - @return {Boolean} - @private - */ - isEmpty() { - return this.size === 0; - } - - /** - @method has - @param obj - @return {Boolean} - @private - */ - has(obj) { - if (this.size === 0) { - return false; - } - - let guid = guidFor(obj); - let presenceSet = this.presenceSet; - - return presenceSet[guid] === true; - } - - /** - @method forEach - @param {Function} fn - @param self - @private - */ - forEach(fn /*, ...thisArg*/) { - assert(`${Object.prototype.toString.call(fn)} is not a function`, typeof fn === 'function'); - - if (this.size === 0) { - return; - } - - let list = this.list; - - if (arguments.length === 2) { - for (let i = 0; i < list.length; i++) { - fn.call(arguments[1], list[i]); - } - } else { - for (let i = 0; i < list.length; i++) { - fn(list[i]); - } - } - } - - /** - @method toArray - @return {Array} - @private - */ - toArray() { - return this.list.slice(); - } - - /** - @method copy - @return {Ember.OrderedSet} - @private - */ - copy() { - let Constructor = this.constructor; - let set = new Constructor(); - - set.presenceSet = copyNull(this.presenceSet); - set.list = this.toArray(); - set.size = this.size; - - return set; - } - }; - - OrderedSet = class OrderedSet extends __OrderedSet__ { - constructor() { - super(); - deprecate('Use of @ember/OrderedSet is deprecated. Please use native `Map` instead', false, { - id: 'ember-map-deprecation', - until: '3.5.0', - }); - } - }; -} - -export { __OrderedSet__ }; -export default OrderedSet; diff --git a/packages/@ember/map/lib/utils.js b/packages/@ember/map/lib/utils.js deleted file mode 100644 index 7c53faf91a4..00000000000 --- a/packages/@ember/map/lib/utils.js +++ /dev/null @@ -1,29 +0,0 @@ -import { MAP, ORDERED_SET } from '@ember/deprecated-features'; - -let copyNull, copyMap; - -if (MAP || ORDERED_SET) { - copyNull = function copyNull(obj) { - let output = Object.create(null); - - for (let prop in obj) { - // hasOwnPropery is not needed because obj is Object.create(null); - output[prop] = obj[prop]; - } - - return output; - }; - - copyMap = function copyMap(original, newObject) { - let keys = original._keys.copy(); - let values = copyNull(original._values); - - newObject._keys = keys; - newObject._values = values; - newObject.size = original.size; - - return newObject; - }; -} - -export { copyMap, copyNull }; diff --git a/packages/@ember/map/tests/map_test.js b/packages/@ember/map/tests/map_test.js deleted file mode 100644 index a0179b0876f..00000000000 --- a/packages/@ember/map/tests/map_test.js +++ /dev/null @@ -1,577 +0,0 @@ -import Map from '..'; -import MapWithDefault from '../with-default'; -import OrderedSet, { __OrderedSet__ } from '../lib/ordered-set'; -import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; - -let object, number, string, map, variety; -const varieties = [['Map', Map], ['MapWithDefault', MapWithDefault]]; - -function testMap(nameAndFunc) { - variety = nameAndFunc[0]; - - moduleFor( - 'Ember.' + variety + ' (forEach and get are implicitly tested)', - class extends AbstractTestCase { - beforeEach() { - object = {}; - number = 42; - string = 'foo'; - - expectDeprecation( - () => { - map = nameAndFunc[1].create(); - }, - 'Use of @ember/Map is deprecated. Please use native `Map` instead', - { id: 'ember-map-deprecation', until: '3.5.0' } - ); - } - - ['@test set'](assert) { - map.set(object, 'winning'); - map.set(number, 'winning'); - map.set(string, 'winning'); - - mapHasEntries(assert, [[object, 'winning'], [number, 'winning'], [string, 'winning']]); - - map.set(object, 'losing'); - map.set(number, 'losing'); - map.set(string, 'losing'); - - mapHasEntries(assert, [[object, 'losing'], [number, 'losing'], [string, 'losing']]); - - assert.equal(map.has('nope'), false, 'expected the key `nope` to not be present'); - assert.equal(map.has({}), false, 'expected they key `{}` to not be present'); - } - - ['@test set chaining'](assert) { - map - .set(object, 'winning') - .set(number, 'winning') - .set(string, 'winning'); - - mapHasEntries(assert, [[object, 'winning'], [number, 'winning'], [string, 'winning']]); - - map - .set(object, 'losing') - .set(number, 'losing') - .set(string, 'losing'); - - mapHasEntries(assert, [[object, 'losing'], [number, 'losing'], [string, 'losing']]); - - assert.equal(map.has('nope'), false, 'expected the key `nope` to not be present'); - assert.equal(map.has({}), false, 'expected they key `{}` to not be present'); - } - - ['@test with key with undefined value'](assert) { - map.set('foo', undefined); - - map.forEach(function(value, key) { - assert.equal(value, undefined); - assert.equal(key, 'foo'); - }); - - assert.ok(map.has('foo'), 'has key foo, even with undefined value'); - - assert.equal(map.size, 1); - } - - ['@test arity of forEach is 1 – es6 23.1.3.5'](assert) { - assert.equal(map.forEach.length, 1, 'expected arity for map.forEach is 1'); - } - - ['@test forEach throws without a callback as the first argument'](assert) { - assert.equal(map.forEach.length, 1, 'expected arity for map.forEach is 1'); - } - - ['@test has empty collection'](assert) { - assert.equal(map.has('foo'), false); - assert.equal(map.has(), false); - } - - ['@test delete'](assert) { - expectNoDeprecation(); - - map.set(object, 'winning'); - map.set(number, 'winning'); - map.set(string, 'winning'); - - map.delete(object); - map.delete(number); - map.delete(string); - - // doesn't explode - map.delete({}); - - mapHasEntries(assert, []); - } - - ['@test copy and then update'](assert) { - map.set(object, 'winning'); - map.set(number, 'winning'); - map.set(string, 'winning'); - - let map2; - expectDeprecation( - () => { - map2 = map.copy(); - }, - 'Use of @ember/Map is deprecated. Please use native `Map` instead', - { id: 'ember-map-deprecation', until: '3.5.0' } - ); - - map2.set(object, 'losing'); - map2.set(number, 'losing'); - map2.set(string, 'losing'); - - mapHasEntries(assert, [[object, 'winning'], [number, 'winning'], [string, 'winning']]); - - mapHasEntries(assert, [[object, 'losing'], [number, 'losing'], [string, 'losing']], map2); - } - - ['@test copy and then delete'](assert) { - map.set(object, 'winning'); - map.set(number, 'winning'); - map.set(string, 'winning'); - - let map2; - expectDeprecation( - () => { - map2 = map.copy(); - }, - 'Use of @ember/Map is deprecated. Please use native `Map` instead', - { id: 'ember-map-deprecation', until: '3.5.0' } - ); - - map2.delete(object); - map2.delete(number); - map2.delete(string); - - mapHasEntries(assert, [[object, 'winning'], [number, 'winning'], [string, 'winning']]); - - mapHasEntries(assert, [], map2); - } - - ['@test size'](assert) { - //Add a key twice - assert.equal(map.size, 0); - map.set(string, 'a string'); - assert.equal(map.size, 1); - map.set(string, 'the same string'); - assert.equal(map.size, 1); - - //Add another - map.set(number, 'a number'); - assert.equal(map.size, 2); - - //Remove one that doesn't exist - map.delete('does not exist'); - assert.equal(map.size, 2); - - //Check copy - expectDeprecation( - () => { - let copy = map.copy(); - assert.equal(copy.size, 2); - }, - 'Use of @ember/Map is deprecated. Please use native `Map` instead', - { id: 'ember-map-deprecation', until: '3.5.0' } - ); - - //Remove a key twice - map.delete(number); - assert.equal(map.size, 1); - map.delete(number); - assert.equal(map.size, 1); - - //Remove the last key - map.delete(string); - assert.equal(map.size, 0); - map.delete(string); - assert.equal(map.size, 0); - } - - ['@test forEach without proper callback'](assert) { - expectAssertion(function() { - map.forEach(); - }, '[object Undefined] is not a function'); - - expectAssertion(function() { - map.forEach(undefined); - }, '[object Undefined] is not a function'); - - expectAssertion(function() { - map.forEach(1); - }, '[object Number] is not a function'); - - expectAssertion(function() { - map.forEach({}); - }, '[object Object] is not a function'); - - map.forEach(function(value, key) { - map.delete(key); - }); - // ensure the error happens even if no data is present - assert.equal(map.size, 0); - expectAssertion(function() { - map.forEach({}); - }, '[object Object] is not a function'); - } - - ['@test forEach basic'](assert) { - map.set('a', 1); - map.set('b', 2); - map.set('c', 3); - - let iteration = 0; - - let expectations = [ - { value: 1, key: 'a', context: unboundThis }, - { value: 2, key: 'b', context: unboundThis }, - { value: 3, key: 'c', context: unboundThis }, - ]; - - map.forEach(function(value, key, theMap) { - let expectation = expectations[iteration]; - - assert.equal(value, expectation.value, 'value should be correct'); - assert.equal(key, expectation.key, 'key should be correct'); - assert.equal(this, expectation.context, 'context should be as if it was unbound'); - assert.equal(map, theMap, 'map being iterated over should be passed in'); - - iteration++; - }); - - assert.equal(iteration, 3, 'expected 3 iterations'); - } - - ['@test forEach basic /w context'](assert) { - map.set('a', 1); - map.set('b', 2); - map.set('c', 3); - - let iteration = 0; - let context = {}; - let expectations = [ - { value: 1, key: 'a', context: context }, - { value: 2, key: 'b', context: context }, - { value: 3, key: 'c', context: context }, - ]; - - map.forEach(function(value, key, theMap) { - let expectation = expectations[iteration]; - - assert.equal(value, expectation.value, 'value should be correct'); - assert.equal(key, expectation.key, 'key should be correct'); - assert.equal(this, expectation.context, 'context should be as if it was unbound'); - assert.equal(map, theMap, 'map being iterated over should be passed in'); - - iteration++; - }, context); - - assert.equal(iteration, 3, 'expected 3 iterations'); - } - - ['@test forEach basic /w deletion while enumerating'](assert) { - map.set('a', 1); - map.set('b', 2); - map.set('c', 3); - - let iteration = 0; - - let expectations = [ - { value: 1, key: 'a', context: unboundThis }, - { value: 2, key: 'b', context: unboundThis }, - ]; - - map.forEach(function(value, key, theMap) { - if (iteration === 0) { - map.delete('c'); - } - - let expectation = expectations[iteration]; - - assert.equal(value, expectation.value, 'value should be correct'); - assert.equal(key, expectation.key, 'key should be correct'); - assert.equal(this, expectation.context, 'context should be as if it was unbound'); - assert.equal(map, theMap, 'map being iterated over should be passed in'); - - iteration++; - }); - - assert.equal(iteration, 2, 'expected 3 iterations'); - } - - ['@test forEach basic /w addition while enumerating'](assert) { - map.set('a', 1); - map.set('b', 2); - map.set('c', 3); - - let iteration = 0; - - let expectations = [ - { value: 1, key: 'a', context: unboundThis }, - { value: 2, key: 'b', context: unboundThis }, - { value: 3, key: 'c', context: unboundThis }, - { value: 4, key: 'd', context: unboundThis }, - ]; - - map.forEach(function(value, key, theMap) { - if (iteration === 0) { - map.set('d', 4); - } - - let expectation = expectations[iteration]; - - assert.equal(value, expectation.value, 'value should be correct'); - assert.equal(key, expectation.key, 'key should be correct'); - assert.equal(this, expectation.context, 'context should be as if it was unbound'); - assert.equal(map, theMap, 'map being iterated over should be passed in'); - - iteration++; - }); - - assert.equal(iteration, 4, 'expected 3 iterations'); - } - - ['@test clear'](assert) { - let iterations = 0; - - map.set('a', 1); - map.set('b', 2); - map.set('c', 3); - map.set('d', 4); - - assert.equal(map.size, 4); - - map.forEach(function() { - iterations++; - }); - assert.equal(iterations, 4); - - map.clear(); - assert.equal(map.size, 0); - iterations = 0; - map.forEach(function() { - iterations++; - }); - assert.equal(iterations, 0); - } - - ['@skip -0'](assert) { - assert.equal(map.has(-0), false); - assert.equal(map.has(0), false); - - map.set(-0, 'zero'); - - assert.equal(map.has(-0), true); - assert.equal(map.has(0), true); - - assert.equal(map.get(0), 'zero'); - assert.equal(map.get(-0), 'zero'); - - map.forEach(function(value, key) { - assert.equal(1 / key, Infinity, 'spec says key should be positive zero'); - }); - } - - ['@test NaN'](assert) { - assert.equal(map.has(NaN), false); - - map.set(NaN, 'not-a-number'); - - assert.equal(map.has(NaN), true); - - assert.equal(map.get(NaN), 'not-a-number'); - } - - ['@test NaN Boxed'](assert) { - let boxed = new Number(NaN); - assert.equal(map.has(boxed), false); - - map.set(boxed, 'not-a-number'); - - assert.equal(map.has(boxed), true); - assert.equal(map.has(NaN), false); - - assert.equal(map.get(NaN), undefined); - assert.equal(map.get(boxed), 'not-a-number'); - } - - ['@test 0 value'](assert) { - let obj = {}; - assert.equal(map.has(obj), false); - - assert.equal(map.size, 0); - map.set(obj, 0); - assert.equal(map.size, 1); - - assert.equal(map.has(obj), true); - assert.equal(map.get(obj), 0); - - map.delete(obj); - assert.equal(map.has(obj), false); - assert.equal(map.get(obj), undefined); - assert.equal(map.size, 0); - } - } - ); - - let mapHasLength = function(assert, expected, theMap) { - theMap = theMap || map; - - let length = 0; - theMap.forEach(function() { - length++; - }); - - assert.equal(length, expected, 'map should contain ' + expected + ' items'); - }; - - let mapHasEntries = function(assert, entries, theMap) { - theMap = theMap || map; - - for (let i = 0; i < entries.length; i++) { - assert.equal(theMap.get(entries[i][0]), entries[i][1]); - assert.equal(theMap.has(entries[i][0]), true); - } - - mapHasLength(assert, entries.length, theMap); - }; - - let unboundThis; - - (function() { - unboundThis = this; - })(); -} - -for (let i = 0; i < varieties.length; i++) { - testMap(varieties[i]); -} - -moduleFor( - 'MapWithDefault - default values', - class extends AbstractTestCase { - ['@test Retrieving a value that has not been set returns and sets a default value'](assert) { - let map; - expectDeprecation( - () => { - map = MapWithDefault.create({ - defaultValue(key) { - return [key]; - }, - }); - }, - 'Use of @ember/Map is deprecated. Please use native `Map` instead', - { id: 'ember-map-deprecation', until: '3.5.0' } - ); - - let value = map.get('ohai'); - assert.deepEqual(value, ['ohai']); - - assert.strictEqual(value, map.get('ohai')); - } - - ['@test Map.prototype.constructor'](assert) { - expectDeprecation( - () => { - let map = new Map(); - assert.equal(map.constructor, Map); - }, - 'Use of @ember/Map is deprecated. Please use native `Map` instead', - { id: 'ember-map-deprecation', until: '3.5.0' } - ); - } - - ['@test MapWithDefault.prototype.constructor'](assert) { - expectDeprecation( - () => { - let map = new MapWithDefault({ - defaultValue(key) { - return key; - }, - }); - assert.equal(map.constructor, MapWithDefault); - }, - 'Use of @ember/Map is deprecated. Please use native `Map` instead', - { id: 'ember-map-deprecation', until: '3.5.0' } - ); - } - - ['@test Copying a MapWithDefault copies the default value'](assert) { - let map; - expectDeprecation( - () => { - map = MapWithDefault.create({ - defaultValue(key) { - return [key]; - }, - }); - }, - 'Use of @ember/Map is deprecated. Please use native `Map` instead', - { id: 'ember-map-deprecation', until: '3.5.0' } - ); - - map.set('ohai', 1); - map.get('bai'); - - let map2; - expectDeprecation( - () => { - map2 = map.copy(); - }, - 'Use of @ember/Map is deprecated. Please use native `Map` instead', - { id: 'ember-map-deprecation', until: '3.5.0' } - ); - - assert.equal(map2.get('ohai'), 1); - assert.deepEqual(map2.get('bai'), ['bai']); - - map2.set('kthx', 3); - - assert.deepEqual(map.get('kthx'), ['kthx']); - assert.equal(map2.get('kthx'), 3); - - assert.deepEqual(map2.get('default'), ['default']); - - map2.defaultValue = key => ['tom is on', key]; - - assert.deepEqual(map2.get('drugs'), ['tom is on', 'drugs']); - } - } -); - -moduleFor( - 'OrderedSet', - class extends AbstractTestCase { - beforeEach() { - object = {}; - number = 42; - string = 'foo'; - - expectDeprecation( - () => { - map = OrderedSet.create(); - }, - 'Use of @ember/OrderedSet is deprecated. Please use native `Map` instead', - { id: 'ember-map-deprecation', until: '3.5.0' } - ); - } - - ['@test add returns the set'](assert) { - let obj = {}; - assert.equal(map.add(obj), map); - assert.equal(map.add(obj), map, 'when it is already in the set'); - } - } -); - -moduleFor( - '__OrderedSet__', - class extends AbstractTestCase { - ['@test private __OrderedSet__ can be created without deprecation']() { - expectNoDeprecation(); - __OrderedSet__.create(); - } - } -); diff --git a/packages/@ember/map/with-default.js b/packages/@ember/map/with-default.js deleted file mode 100644 index d492ddb2f82..00000000000 --- a/packages/@ember/map/with-default.js +++ /dev/null @@ -1,87 +0,0 @@ -import { deprecate } from '@ember/debug'; -import Map from './index'; -import { copyMap } from './lib/utils'; -import { MAP } from '@ember/deprecated-features'; - -let MapWithDefault; - -if (MAP) { - /** - @class MapWithDefault - @extends Map - @private - @constructor - @param [options] - @param {*} [options.defaultValue] -*/ - MapWithDefault = class MapWithDefault extends Map { - constructor(options) { - deprecate( - 'Use of @ember/MapWithDefault is deprecated. Please use native `Map` instead', - false, - { - id: 'ember-map-deprecation', - until: '3.5.0', - } - ); - - super(); - this.defaultValue = options.defaultValue; - } - - /** - @method create - @static - @param [options] - @param {*} [options.defaultValue] - @return {MapWithDefault|Map} If options are passed, returns - `MapWithDefault` otherwise returns `EmberMap` - @private - @deprecated use native `Map` instead - */ - static create(options) { - if (options) { - return new MapWithDefault(options); - } else { - return new Map(); - } - } - - /** - Retrieve the value associated with a given key. - - @method get - @param {*} key - @return {*} the value associated with the key, or the default value - @private - */ - get(key) { - let hasValue = this.has(key); - - if (hasValue) { - return super.get(key); - } else { - let defaultValue = this.defaultValue(key); - this.set(key, defaultValue); - return defaultValue; - } - } - - /** - @method copy - @return {MapWithDefault} - @private - */ - copy() { - let Constructor = this.constructor; - return copyMap( - this, - new Constructor({ - defaultValue: this.defaultValue, - }) - ); - } - }; -} - -export default MapWithDefault; diff --git a/packages/ember/index.js b/packages/ember/index.js index 7785566e688..b3a0231a015 100644 --- a/packages/ember/index.js +++ b/packages/ember/index.js @@ -124,9 +124,6 @@ import Resolver from '@ember/application/globals-resolver'; import ApplicationInstance from '@ember/application/instance'; import Engine from '@ember/engine'; import EngineInstance from '@ember/engine/instance'; -import Map from '@ember/map'; -import MapWithDefault from '@ember/map/with-default'; -import OrderedSet, { __OrderedSet__ } from '@ember/map/lib/ordered-set'; import { assign, merge } from '@ember/polyfills'; import { LOGGER, EMBER_EXTEND_PROTOTYPES } from '@ember/deprecated-features'; @@ -179,12 +176,6 @@ Ember.ApplicationInstance = ApplicationInstance; Ember.Engine = Engine; Ember.EngineInstance = EngineInstance; -// ****@ember/map**** -Ember.OrderedSet = OrderedSet; -Ember.__OrderedSet__ = __OrderedSet__; -Ember.Map = Map; -Ember.MapWithDefault = MapWithDefault; - // ****@ember/polyfills**** Ember.assign = assign; Ember.merge = merge; diff --git a/packages/ember/tests/reexports_test.js b/packages/ember/tests/reexports_test.js index e41bdab930b..216b3616fbe 100644 --- a/packages/ember/tests/reexports_test.js +++ b/packages/ember/tests/reexports_test.js @@ -151,9 +151,6 @@ let allExports = [ ['unwatch', '@ember/-internals/metal'], ['destroy', '@ember/-internals/meta', 'deleteMeta'], ['libraries', '@ember/-internals/metal'], - ['OrderedSet', '@ember/map/lib/ordered-set', 'default'], - ['Map', '@ember/map', 'default'], - ['MapWithDefault', '@ember/map/with-default', 'default'], ['getProperties', '@ember/-internals/metal'], ['setProperties', '@ember/-internals/metal'], ['expandProperties', '@ember/-internals/metal'], diff --git a/tests/docs/expected.js b/tests/docs/expected.js index 94e1e3d34d1..b87b07bc25a 100644 --- a/tests/docs/expected.js +++ b/tests/docs/expected.js @@ -62,7 +62,6 @@ module.exports = { 'active', 'activeClass', 'adapter', - 'add', 'addArrayObserver', 'addListener', 'addObject', @@ -157,7 +156,6 @@ module.exports = { 'defer', 'deferReadiness', 'defineProperty', - 'delete', 'deleteMeta', 'denodeify', 'deprecate',