Skip to content

Commit

Permalink
Add deprecation for legacyKey
Browse files Browse the repository at this point in the history
  • Loading branch information
fsmanuel committed Feb 7, 2018
1 parent d22d13d commit 3cdf12e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export default Ember.Component.extend({
`model` Optional string - The dependent property. Must be an ember data model or an object with `modelName` and `id` properties. (It is still experimental)

`options` are:
- `legacyKey` String
- `legacyKey` String - **Deprecated see [Deprecations](#deprecations)**


#### Methods
Expand Down Expand Up @@ -391,6 +391,15 @@ export default Route.extend({
- `download` Boolean (default `false`)
- `filename` String (default ember-data.json)
## Deprecations
### storageFor - legacyKey
until: 2.0.0
id: ember-local-storage.storageFor.options.legacyKey
Using `legacyKey` has been deprecated and will be removed in version 2.0.0. You should migrate your key to the new format. For `storageFor('settings')` that would be `storage:settings`.
## Running
* `ember serve`
Expand Down
11 changes: 10 additions & 1 deletion addon/helpers/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const {
getOwner,
String: {
dasherize
}
},
deprecate
} = Ember;

const assign = Ember.assign || Ember.merge;
Expand Down Expand Up @@ -38,6 +39,7 @@ function getStorage(name) {

let storages = {};

// TODO: v2.0 - Remove options
function storageFor(key, modelName, options = {}) {
if (arguments.length === 2 && typeof modelName === 'object') {
options = modelName;
Expand Down Expand Up @@ -85,6 +87,7 @@ function storageFor(key, modelName, options = {}) {
* Looks up the storage factory on the container and sets initial state
* on the instance if desired.
*/
// TODO: v2.0 - Remove options and legacyKey
function createStorage(context, key, modelKey, options) {
const owner = getOwner(context);
const factoryType = 'storage';
Expand All @@ -95,6 +98,12 @@ function createStorage(context, key, modelKey, options) {
owner.registerOptionsForType(factoryType, { instantiate: false });

if (options.legacyKey) {
deprecate('Using legacyKey has been deprecated and will be removed in version 2.0.0', false, {
id: 'ember-local-storage.storageFor.options.legacyKey',
until: '2.0.0',
url: 'https://github.com/funkensturm/ember-local-storage#deprecations'
});

storageKey = options.legacyKey;
} else {
storageKey = modelKey ? `${storageFactory}:${modelKey}` : storageFactory;
Expand Down

0 comments on commit 3cdf12e

Please sign in to comment.