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 array, object, and storage mixins and helpers/utils #374

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Mixin from '@ember/object/mixin';
import { set, get } from '@ember/object';
import { isArray, A } from '@ember/array';
import { getStorage } from '../helpers/storage';
import { getStorage } from 'ember-local-storage/helpers/storage';
import { copy } from 'ember-copy';
import { getOwner } from '@ember/application';
import { associateDestroyableChild } from '@ember/destroyable';
Expand Down
File renamed without changes.
36 changes: 1 addition & 35 deletions addon/adapters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ export default class BaseAdapter extends JSONAPIAdapter {
_debug = false;
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;
Expand Down Expand Up @@ -96,49 +92,19 @@ export default class BaseAdapter extends JSONAPIAdapter {
return super.deleteRecord(...arguments);
}

// Polyfill queryRecord
queryRecord(store, type, query) {
queryRecord() {
let records = super.queryRecord(...arguments);

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

records = this.ajax(url, 'GET', { data: query });
}

return records.then(function (result) {
return { data: result.data[0] || null };
});
}

// TODO: v2.0 - What are the defaults now? What versions to support?
// Delegate to _handleStorageRequest
ajax() {
return this._handleStorageRequest.apply(this, arguments);
}

// Delegate to _handleStorageRequest
makeRequest(request) {
return this._handleStorageRequest(request.url, request.method, {
data: request.data,
});
}

// Work arround ds-improved-ajax Feature Flag
_makeRequest() {
return this.makeRequest.apply(this, arguments);
}

// Remove the ajax() deprecation warning
_hasCustomizedAjax() {
return false;
}

// Delegate to _handle${type}Request
_handleStorageRequest(url, type, options = {}) {
if (this._debug) {
Expand Down
4 changes: 2 additions & 2 deletions addon/adapters/local.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { get } from '@ember/object';
import BaseAdapter from './base';
import { getStorage, _buildKey } from '../helpers/storage';
import StorageArray from '../local/array';
import { getStorage, _buildKey } from 'ember-local-storage/helpers/storage';
import StorageArray from 'ember-local-storage/local/array';
import { getOwner } from '@ember/application';

export default class LocalStorageAdapter extends BaseAdapter {
Expand Down
4 changes: 2 additions & 2 deletions addon/adapters/session.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { get } from '@ember/object';
import BaseAdapter from './base';
import { getStorage, _buildKey } from '../helpers/storage';
import StorageArray from '../session/array';
import { getStorage, _buildKey } from 'ember-local-storage/helpers/storage';
import StorageArray from 'ember-local-storage/session/array';
import { getOwner } from '@ember/application';

export default class SessionStorageAdapter extends BaseAdapter {
Expand Down
15 changes: 13 additions & 2 deletions addon/local/array.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { A } from '@ember/array';
import ArrayProxy from '@ember/array/proxy';
import ArrayProxyMixin from '../mixins/array';
import { set } from '@ember/object';
import StorageProxyMixin from 'ember-local-storage/-private/legacy-mixins/storage';
import { save } from 'ember-local-storage/-private/legacy-utils';

export default ArrayProxy.extend(ArrayProxyMixin, {
export default ArrayProxy.extend(StorageProxyMixin, {
_initialContent: A(),
_storageType: 'local',

_clear() {
set(this, 'content', A());
},

replaceContent: save,
reset: save,
});
15 changes: 13 additions & 2 deletions addon/local/object.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { set } from '@ember/object';
import ObjectProxy from '@ember/object/proxy';
import ObjectProxyMixin from '../mixins/object';
import StorageProxyMixin from 'ember-local-storage/-private/legacy-mixins/storage';
import { save, saveIfChanged } from 'ember-local-storage/-private/legacy-utils';

export default ObjectProxy.extend(ObjectProxyMixin, {
export default ObjectProxy.extend(StorageProxyMixin, {
_initialContent: {},
_storageType: 'local',

_clear() {
set(this, 'content', {});
},

setUnknownProperty: saveIfChanged,
set: saveIfChanged,
setProperties: save,
});
15 changes: 0 additions & 15 deletions addon/mixins/array.js

This file was deleted.

15 changes: 0 additions & 15 deletions addon/mixins/object.js

This file was deleted.

22 changes: 11 additions & 11 deletions addon/serializers/serializer.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import JSONAPISerializer from '@ember-data/serializer/json-api';

export default JSONAPISerializer.extend({
export default class Serializer extends JSONAPISerializer {
shouldSerializeHasMany() {
return true;
},
}

serializeBelongsTo() {
this._fixSerializeBelongsTo(...arguments);
},

serializeHasMany() {
this._fixSerializeHasMany(...arguments);
},
}

_fixSerializeBelongsTo(snapshot, json, relationship) {
let key = relationship.key;
Expand Down Expand Up @@ -43,7 +39,11 @@ export default JSONAPISerializer.extend({
json.relationships[payloadKey] = { data };
}
}
},
}

serializeHasMany() {
this._fixSerializeHasMany(...arguments);
}

_fixSerializeHasMany(snapshot, json, relationship) {
let key = relationship.key;
Expand All @@ -66,7 +66,7 @@ export default JSONAPISerializer.extend({
let data = new Array(nonNewHasMany.length);

for (let i = 0; i < nonNewHasMany.length; i++) {
let item = hasMany[i];
let item = nonNewHasMany[i];
let payloadType = this.payloadKeyFromModelName(item.modelName);

data[i] = {
Expand All @@ -78,5 +78,5 @@ export default JSONAPISerializer.extend({
json.relationships[payloadKey] = { data };
}
}
},
});
}
}
15 changes: 13 additions & 2 deletions addon/session/array.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { A } from '@ember/array';
import ArrayProxy from '@ember/array/proxy';
import ArrayProxyMixin from '../mixins/array';
import { set } from '@ember/object';
import StorageProxyMixin from 'ember-local-storage/-private/legacy-mixins/storage';
import { save } from 'ember-local-storage/-private/legacy-utils';

export default ArrayProxy.extend(ArrayProxyMixin, {
export default ArrayProxy.extend(StorageProxyMixin, {
_initialContent: A(),
_storageType: 'session',

_clear() {
set(this, 'content', A());
},

replaceContent: save,
reset: save,
});
15 changes: 13 additions & 2 deletions addon/session/object.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { set } from '@ember/object';
import ObjectProxy from '@ember/object/proxy';
import ObjectProxyMixin from '../mixins/object';
import StorageProxyMixin from 'ember-local-storage/-private/legacy-mixins/storage';
import { save, saveIfChanged } from 'ember-local-storage/-private/legacy-utils';

export default ObjectProxy.extend(ObjectProxyMixin, {
export default ObjectProxy.extend(StorageProxyMixin, {
_initialContent: {},
_storageType: 'session',

_clear() {
set(this, 'content', {});
},

setUnknownProperty: saveIfChanged,
set: saveIfChanged,
setProperties: save,
});
2 changes: 2 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ module.exports = async function () {
'ember-auto-import': '^2.2.0',
'ember-data': 'latest',
'ember-source': await getChannelURL('release'),
'ember-resolver': '10.0.0',
'@ember/string': '3.0.1',
},
},
},
Expand Down
Loading