Skip to content

Commit

Permalink
Merge pull request #363 from funkensturm/ember-data-imports
Browse files Browse the repository at this point in the history
Change ember-data import to @ember-data
  • Loading branch information
fsmanuel authored Sep 4, 2022
2 parents 1c49ddc + 68fab3d commit aa1f837
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 66 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module.exports = {
'ember/no-mixins': 'off',
'ember/no-new-mixins': 'off',
'ember/no-string-prototype-extensions': 'off',
'ember/use-ember-data-rfc-395-imports': 'off',
},
overrides: [
// node files
Expand Down
4 changes: 1 addition & 3 deletions addon/adapters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import RSVP from 'rsvp';
import { run } from '@ember/runloop';
import { isEmpty, typeOf } from '@ember/utils';
import { computed, get } from '@ember/object';
import DS from 'ember-data';
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import ImportExportMixin from '../mixins/adapters/import-export';
import { _buildKey } from '../helpers/storage';

const getKeys = Object.keys || keys;

const { JSONAPIAdapter } = DS;

// Ember data ships with ember-inflector
import { singularize, pluralize } from 'ember-inflector';

Expand Down
6 changes: 3 additions & 3 deletions addon/initializers/local-storage-adapter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import DS from 'ember-data';
import Store from '@ember-data/store';
import {
importData,
exportData,
} from 'ember-local-storage/helpers/import-export';

export function initialize() {
if (!DS.Store.prototype._emberLocalStoragePatched) {
DS.Store.reopen({
if (!Store.prototype._emberLocalStoragePatched) {
Store.reopen({
_emberLocalStoragePatched: true,
importData: function (json, options) {
return importData(this, json, options);
Expand Down
30 changes: 6 additions & 24 deletions addon/serializers/serializer.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
import DS from 'ember-data';

const { JSONAPISerializer } = DS;

const emberDataVersionOlderThan3Point1 = DS.VERSION.match(/^[0-2]\.|^3\.0/);
import JSONAPISerializer from '@ember-data/serializer/json-api';

export default JSONAPISerializer.extend({
// Serialization behavior
// Can be removed (_shouldSerializeHasMany) removed in ember data 3.0.0
// https://github.com/emberjs/data/pull/5290
_shouldSerializeHasMany: function () {
return true;
},
shouldSerializeHasMany: function () {
shouldSerializeHasMany() {
return true;
},

serializeBelongsTo(snapshot, json, relationship) {
if (emberDataVersionOlderThan3Point1) {
this._super.apply(this, arguments);
} else {
this._fixSerializeBelongsTo(snapshot, json, relationship);
}
serializeBelongsTo() {
this._fixSerializeBelongsTo(...arguments);
},

serializeHasMany(snapshot, json, relationship) {
if (emberDataVersionOlderThan3Point1) {
this._super.apply(this, arguments);
} else {
this._fixSerializeHasMany(snapshot, json, relationship);
}
serializeHasMany() {
this._fixSerializeHasMany(...arguments);
},

_fixSerializeBelongsTo(snapshot, json, relationship) {
Expand Down
4 changes: 1 addition & 3 deletions tests/dummy/app/models/blog/post.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import DS from 'ember-data';

const { Model, attr, belongsTo, hasMany } = DS;
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';

export default Model.extend({
name: attr('string'),
Expand Down
4 changes: 1 addition & 3 deletions tests/dummy/app/models/book-publication.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import DS from 'ember-data';

const { Model, attr, hasMany } = DS;
import Model, { attr, hasMany } from '@ember-data/model';

export default Model.extend({
name: attr('string'),
Expand Down
4 changes: 1 addition & 3 deletions tests/dummy/app/models/comment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import DS from 'ember-data';

const { Model, attr, belongsTo } = DS;
import Model, { attr, belongsTo } from '@ember-data/model';

export default Model.extend({
name: attr('string'),
Expand Down
4 changes: 1 addition & 3 deletions tests/dummy/app/models/pet.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import DS from 'ember-data';

const { Model, attr, hasMany } = DS;
import Model, { attr, hasMany } from '@ember-data/model';

export default Model.extend({
name: attr('string'),
Expand Down
4 changes: 1 addition & 3 deletions tests/dummy/app/models/post.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import DS from 'ember-data';

const { Model, attr, belongsTo, hasMany } = DS;
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';

export default Model.extend({
name: attr('string'),
Expand Down
4 changes: 1 addition & 3 deletions tests/dummy/app/models/project.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import DS from 'ember-data';

const { Model, attr, hasMany } = DS;
import Model, { attr, hasMany } from '@ember-data/model';

export default Model.extend({
name: attr('string'),
Expand Down
4 changes: 1 addition & 3 deletions tests/dummy/app/models/task.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import DS from 'ember-data';

const { Model, attr, belongsTo, hasMany } = DS;
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';

export default Model.extend({
name: attr('string'),
Expand Down
4 changes: 1 addition & 3 deletions tests/dummy/app/models/user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import DS from 'ember-data';

const { Model, attr, hasMany } = DS;
import Model, { attr, hasMany } from '@ember-data/model';

export default Model.extend({
name: attr('string'),
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/adapters/application-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { run } from '@ember/runloop';
import DS from 'ember-data';
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

const { AdapterError, Model, attr } = DS;
import { run } from '@ember/runloop';
import Model, { attr } from '@ember-data/model';
import AdapterError from '@ember-data/adapter/error';

let SimpleModel = Model.extend({
prop: attr('string'),
Expand Down
14 changes: 6 additions & 8 deletions tests/unit/models/post-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { get } from '@ember/object';
import { run } from '@ember/runloop';
import DS from 'ember-data';
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

import { get } from '@ember/object';
import { run } from '@ember/runloop';

import {
registerConfigEnvironment,
setConfigEnvironment,
Expand Down Expand Up @@ -194,11 +195,7 @@ module('Unit | Model | post', function (hooks) {
store
.queryRecord('post', { filter: { name: 'Super Name' } })
.then(function (post) {
if (DS.VERSION.match(/^1\.13\./) || DS.VERSION.match(/^2\.[0|1]\./)) {
assert.deepEqual(post, []);
} else {
assert.equal(post, null);
}
assert.equal(post, null);

done();
})
Expand All @@ -207,6 +204,7 @@ module('Unit | Model | post', function (hooks) {
false,
'queryRecord on empty store throws error: ' + error.message
);

done();
});
});
Expand Down

0 comments on commit aa1f837

Please sign in to comment.