Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove 2.0 deprecations #339

Merged
merged 1 commit into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions addon/adapters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ import { singularize, pluralize } from 'ember-inflector';
export default JSONAPIAdapter.extend(ImportExportMixin, {
_debug: false,
_indices: computed(function() { return {}; }),
isNewSerializerAPI: true,
coalesceFindRequests: false,

// TODO: v2.0 - What are the defaults now? What versions to support?
isNewSerializerAPI: true,

// TODO: v2.0 - Can we deprecate or remove that? What are the defaults now? What versions to support?
// Reload behavior
shouldReloadRecord() { return true; },
shouldReloadAll() { return true; },
Expand Down Expand Up @@ -89,6 +92,7 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
if (!records) {
var url = this.buildURL(type.modelName, null, null, 'queryRecord', query);

// TODO: Document why this is needed or remove it!
if (this.sortQueryParams) {
query = this.sortQueryParams(query);
}
Expand All @@ -102,6 +106,7 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
});
},

// TODO: v2.0 - What are the defaults now? What versions to support?
// Delegate to _handleStorageRequest
ajax() {
return this._handleStorageRequest.apply(this, arguments);
Expand Down Expand Up @@ -149,8 +154,8 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {

_handleGETRequest(url, query) {
const { type, id } = this._urlParts(url);
const storage = get(this, '_storage'),
storageKey = this._storageKey(type, id);
const storage = get(this, '_storage');
const storageKey = this._storageKey(type, id);

if (id) {
if (!storage[storageKey]) {
Expand Down Expand Up @@ -208,9 +213,10 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
return null;
},

// TODO: Extract into utility functions in private/query.js
_queryFilter(data, serializer, query = {}) {
const queryType = typeOf(query),
dataType = typeOf(data);
const queryType = typeOf(query);
const dataType = typeOf(data);

if (queryType === 'object' && dataType === 'object') {
return getKeys(query).every((key) => {
Expand Down
45 changes: 10 additions & 35 deletions addon/helpers/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { assert } from '@ember/debug';
import EmberObject, { computed, get } from '@ember/object';
import { getOwner } from '@ember/application';
import { dasherize } from '@ember/string';
import { deprecate } from '@ember/application/deprecations';


const storage = {};
Expand Down Expand Up @@ -32,22 +31,14 @@ function getStorage(name) {

let storages = {};

// TODO: v2.0 - Remove options
function storageFor(key, modelName, options = {}) {
if (arguments.length === 2 && typeof modelName === 'object') {
options = modelName;
modelName = null;
}

assert('The options argument must be an object', typeof options === 'object');

// normalize key
function storageFor(key, modelName) {
// Normalize key
key = dasherize(key);

if (!modelName) {
return computed(function() {
if (!storages[key]) {
storages[key] = createStorage(this, key, null, options);
storages[key] = createStorage(this, key, null);
}

return storages[key];
Expand All @@ -56,20 +47,20 @@ function storageFor(key, modelName, options = {}) {

assert('The second argument must be a string', typeof modelName === 'string');

// TODO: Allow callbacks to delete the storage if model gets deleted
return computed(modelName, function() {
const model = get(this, modelName);

// if the propertyValue is null/undefined we simply return null/undefined
// If the propertyValue is null/undefined we simply return null/undefined
if (!model || typeof model === 'undefined') {
return model;
}

const modelKey = _modelKey(model);
const storageKey = `${key}:${modelKey}`;
// TODO allow callbacks to delete the storage if model gets deleted

if (!storages[storageKey]) {
storages[storageKey] = createStorage(this, key, modelKey, options);
storages[storageKey] = createStorage(this, key, modelKey);
}

return storages[storageKey];
Expand All @@ -80,30 +71,14 @@ 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) {
function createStorage(context, key, modelKey) {
const owner = getOwner(context);
const factoryType = 'storage';
const storageFactory = `${factoryType}:${key}`;

let storageKey;

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;
}

storageKey = _buildKey(context, storageKey);
const storageKey = modelKey ? `${storageFactory}:${modelKey}` : storageFactory;

const defaultState = {
_storageKey: storageKey
_storageKey: _buildKey(context, storageKey)
};
const StorageFactory = owner.factoryFor(storageFactory);

Expand Down Expand Up @@ -143,7 +118,7 @@ function _modelKey(model) {
return `${modelName}:${id}`;
}

// TODO: v2.0 - Make modulePrefix the default
// TODO: v2.0 - Make modulePrefix the default - needs a warning/error
function _getNamespace(appConfig, addonConfig) {
// For backward compatibility this is a opt-in feature
let namespace = addonConfig.namespace;
Expand Down
66 changes: 0 additions & 66 deletions tests/unit/legacy-test.js

This file was deleted.