Skip to content

Commit

Permalink
add deprecation to Location.create
Browse files Browse the repository at this point in the history
  • Loading branch information
bekzod committed Jul 21, 2018
1 parent b8304fb commit aa0712a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
53 changes: 50 additions & 3 deletions packages/ember-routing/lib/location/api.js
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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.
Expand All @@ -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);

Expand All @@ -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;
2 changes: 1 addition & 1 deletion packages/ember-routing/lib/location/hash_location.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,5 @@ export default EmberObject.extend({
if (this._hashchangeHandler) {
window.removeEventListener('hashchange', this._hashchangeHandler);
}
}
},
});

0 comments on commit aa0712a

Please sign in to comment.