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 Aug 20, 2018
1 parent 55a6e88 commit 753d6e7
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 @@ -165,7 +165,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 @@ -392,6 +392,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 753d6e7

Please sign in to comment.