From aa0712a12fbaf468b14ae2d606b3a438147b4e1e Mon Sep 17 00:00:00 2001 From: bekzod Date: Sat, 21 Jul 2018 10:15:46 +0500 Subject: [PATCH] add deprecation to `Location.create` --- packages/ember-routing/lib/location/api.js | 53 +++++++++++++++++-- .../lib/location/hash_location.js | 2 +- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/packages/ember-routing/lib/location/api.js b/packages/ember-routing/lib/location/api.js index 6ed10cbd7fd..da783166aea 100644 --- a/packages/ember-routing/lib/location/api.js +++ b/packages/ember-routing/lib/location/api.js @@ -1,4 +1,7 @@ -import { assert } from '@ember/debug'; +import { assert, deprecate } from '@ember/debug'; +import { HAS_NATIVE_PROXY } from 'ember-utils'; +import { DEBUG } from '@glimmer/env'; + /** @module @ember/routing */ @@ -61,7 +64,7 @@ import { assert } from '@ember/debug'; @class Location @private */ -export default { +const Location = { /** This is deprecated in favor of using the container to lookup the location implementation as desired. @@ -84,6 +87,12 @@ export default { @private */ create(options) { + deprecate( + `\`Location.create\` is deprecated, use the \`container\` to register and lookup the location implementation that you need`, + false, + { id: 'ember-routing.location-create', until: '3.9.0' } + ); + let implementation = options && options.implementation; assert("Location.create: you must specify a 'implementation' option", !!implementation); @@ -96,5 +105,43 @@ export default { return implementationClass.create(...arguments); }, - implementations: {} + _implementations: {}, }; + +if (DEBUG && HAS_NATIVE_PROXY) { + /* globals Proxy Reflect */ + Location._implementations = new Proxy( + {}, + { + set() { + deprecate( + `\`Location.implementations\` is deprecated, use the \`container\` to register and lookup the location implementation that you need`, + false, + { id: 'ember-routing.location-create', until: '3.9.0' } + ); + return Reflect.set(...arguments); + }, + } + ); +} + +Object.defineProperty(Location, 'implementations', { + set: function(val) { + deprecate( + `\`Location.implementations\` is deprecated, use the \`container\` to register and lookup the location implementation that you need`, + false, + { id: 'ember-routing.location-create', until: '3.9.0' } + ); + this._implementations = val; + }, + get: function() { + deprecate( + `\`Location.implementations\` is deprecated, use the \`container\` to register and lookup the location implementation that you need`, + false, + { id: 'ember-routing.location-create', until: '3.9.0' } + ); + return this._implementations; + }, +}); + +export default Location; diff --git a/packages/ember-routing/lib/location/hash_location.js b/packages/ember-routing/lib/location/hash_location.js index b434df499f2..8656aa8dc87 100644 --- a/packages/ember-routing/lib/location/hash_location.js +++ b/packages/ember-routing/lib/location/hash_location.js @@ -168,5 +168,5 @@ export default EmberObject.extend({ if (this._hashchangeHandler) { window.removeEventListener('hashchange', this._hashchangeHandler); } - } + }, });