Skip to content

Commit

Permalink
Fix ember-data imports
Browse files Browse the repository at this point in the history
  • Loading branch information
DubrovinPavel committed Jul 26, 2024
1 parent 217dc79 commit 14a6825
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 104 deletions.
6 changes: 4 additions & 2 deletions addon/stores/base-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { isNone, isEmpty } from '@ember/utils';
import { computed } from '@ember/object';
import $ from 'jquery';
import { getOwner } from '@ember/application';
import Store from '@ember-data/store';
import decorateAdapter from './base-store/decorate-adapter';
import decorateAPICall from './base-store/decorate-api-call';
import QueryObject from '../query/query-object';
import isObject from '../utils/is-object';
import OnlineStore from './online-store';
import CompatibleStore from './compatible-store';

/**
Base class for application store.
Expand All @@ -17,7 +17,7 @@ import OnlineStore from './online-store';
@class Store
@extends <a href="http://emberjs.com/api/data/classes/DS.Store.html">DS.Store</a>
*/
export default class extends Store {
export default class extends CompatibleStore {
/**
Store offline schemas for all databases.
Expand Down Expand Up @@ -136,11 +136,13 @@ export default class extends Store {
if (isNone(this.onlineStore)) {
let onlineStore = OnlineStore.create(owner.ownerInjection());
this.onlineStore = onlineStore;
this.fixLegacyStore(this.onlineStore);
}

// Set offline store.
let offlineStore = owner.lookup('store:local');
this.offlineStore = offlineStore;
this.fixLegacyStore(this.offlineStore);
this.offlineStore.offlineSchema = this.offlineSchema;
}

Expand Down
38 changes: 17 additions & 21 deletions addon/stores/compatible-store.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/*import Store from '@ember-data/store';
import Store from '@ember-data/store';
import { CacheHandler } from '@ember-data/store';
import RequestManager from '@ember-data/request';
import Fetch from '@ember-data/request/fetch';
import {
adapterFor,
cleanup,
LegacyNetworkHandler,
normalize,
pushPayload,
Expand All @@ -15,21 +14,23 @@ import JSONAPICache from '@ember-data/json-api';
import { buildSchema, instantiateRecord, modelFor, teardownRecord } from '@ember-data/model/hooks';

export default class extends Store {
adapterFor = adapterFor;
serializerFor = serializerFor;
pushPayload = pushPayload;
normalize = normalize;
serializeRecord = serializeRecord;
constructor() {
super(...arguments);
if (!this.requestManager) {
this.requestManager = new RequestManager();
this.requestManager.use([LegacyNetworkHandler, Fetch]);
fixLegacyStore(store) {
store.adapterFor ??= adapterFor;
store.serializerFor ??= serializerFor;
store.pushPayload ??= pushPayload;
store.normalize ??= normalize;
store.serializeRecord ??= serializeRecord;
store.createSchemaService ??= this.createSchemaService;
store.createCache ??= this.createCache;
store.instantiateRecord = this.instantiateRecord;
store.teardownRecord = this.teardownRecord;
store.modelFor = this.modelFor;
if (!store.requestManager) {
store.requestManager = new RequestManager();
store.requestManager.use([LegacyNetworkHandler, Fetch]);
}

this.requestManager.useCache(CacheHandler);
store.requestManager.useCache(CacheHandler);
}

createSchemaService() {
Expand All @@ -51,9 +52,4 @@ export default class extends Store {
modelFor(type) {
return (modelFor.call(this, type)) || super.modelFor(type);
}
destroy() {
cleanup.call(this);
super.destroy();
}
}*/
}
4 changes: 2 additions & 2 deletions addon/stores/local-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { computed } from '@ember/object';
import { getOwner } from '@ember/application';
import { isArray } from '@ember/array';
import { assert, debug } from '@ember/debug';
import { cleanup } from '@ember-data/legacy-compat';
import Store from '@ember-data/store';
import { isNone, isBlank } from '@ember/utils';
import RSVP from 'rsvp';
import Store from '@ember-data/store';
import OfflineAdapter from '../adapters/offline';
import QueryBuilder from '../query/builder';
import { cleanup } from '../utils/store-functions';

/**
Store that used in offline mode by default.
Expand Down
5 changes: 2 additions & 3 deletions addon/stores/online-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
import { assert, debug } from '@ember/debug';
import { isNone, isBlank } from '@ember/utils';
import { A } from '@ember/array';
import { cleanup } from '@ember-data/legacy-compat';
import Store from '@ember-data/store';
import RSVP from 'rsvp';
import { isArray } from '@ember/array';
import QueryBuilder from '../query/builder';
import { cleanup } from '../utils/store-functions';

import Store from '@ember-data/store';

/**
Store that used in online mode by default.
Expand Down
15 changes: 0 additions & 15 deletions addon/utils/store-functions.js

This file was deleted.

6 changes: 6 additions & 0 deletions app/ember-data-imports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import DS from 'ember-data';
import RequestManager from '@ember-data/request';
import Fetch from '@ember-data/request/fetch';
import Legacy from '@ember-data/legacy-compat';
import JSONAPICache from '@ember-data/json-api';
import ModelHooks from '@ember-data/model/hooks';
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-flexberry-data",
"version": "5.0.0-beta.2",
"version": "5.0.0-beta.3",
"description": "Support of database projections, JavaScript Query Language and working with several kinds of backends",
"keywords": [
"ember-addon",
Expand Down Expand Up @@ -38,8 +38,7 @@
"dependencies": {
"@babel/core": "^7.24.7",
"ember-cli-babel": "^8.2.0",
"ember-cli-htmlbars": "^6.3.0",
"ember-data": "^5.3.4"
"ember-cli-htmlbars": "^6.3.0"
},
"devDependencies": {
"@babel/eslint-parser": "^7.24.7",
Expand All @@ -54,6 +53,7 @@
"concurrently": "^8.2.2",
"dexie": "^2.0.2",
"ember-auto-import": "^2.7.4",
"ember-data": "^5.3.4",
"ember-cli": "~5.10.0",
"ember-cli-clean-css": "^3.0.0",
"ember-cli-dependency-checker": "^3.3.2",
Expand Down
55 changes: 0 additions & 55 deletions tests/dummy/app/services/store.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
import BaseStore from 'ember-flexberry-data/stores/base-store';
import { CacheHandler } from '@ember-data/store';
import { set } from '@ember/object';
import RequestManager from '@ember-data/request';
import Fetch from '@ember-data/request/fetch';
import {
adapterFor,
LegacyNetworkHandler,
normalize,
pushPayload,
serializeRecord,
serializerFor,
} from '@ember-data/legacy-compat';
import JSONAPICache from '@ember-data/json-api';
import { buildSchema, instantiateRecord, modelFor, teardownRecord } from '@ember-data/model/hooks';

export default class extends BaseStore {
constructor() {
Expand Down Expand Up @@ -56,51 +43,9 @@ export default class extends BaseStore {
});
this.offlineStore.dbName = 'TestDB';

this.fixLegacyStore(this.onlineStore);
this.fixLegacyStore(this.offlineStore);

this._dbInit();
}

fixLegacyStore(store) {
store.adapterFor ??= adapterFor;
store.serializerFor ??= serializerFor;
store.pushPayload ??= pushPayload;
store.normalize ??= normalize;
store.serializeRecord ??= serializeRecord;
store.createSchemaService ??= this.createSchemaService;
store.createCache ??= this.createCache;
store.instantiateRecord = this.instantiateRecord;
store.teardownRecord = this.teardownRecord;
store.modelFor = this.modelFor;
if (!store.requestManager) {
store.requestManager = new RequestManager();
store.requestManager.use([LegacyNetworkHandler, Fetch]);
}

store.requestManager.useCache(CacheHandler);
}

createSchemaService() {
return buildSchema(this);
}

createCache(storeWrapper) {
return new JSONAPICache(storeWrapper);
}

instantiateRecord(identifier, createRecordArgs) {
return instantiateRecord.call(this, identifier, createRecordArgs);
}

teardownRecord(record) {
teardownRecord.call(this, record);
}

modelFor(type) {
return (modelFor.call(this, type)) || super.modelFor(type);
}

offlineModels = {
'i-c-s-soft-s-t-o-r-m-n-e-t-business-audit-objects-audit-entity': true,
'i-c-s-soft-s-t-o-r-m-n-e-t-business-audit-objects-audit-field': true,
Expand Down
2 changes: 1 addition & 1 deletion vendor/ember-flexberry-data/register-version.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* globals Ember */
var version = '5.0.0-beta.2';
var version = '5.0.0-beta.3';
Ember.libraries.register('Ember Flexberry Data', version);

0 comments on commit 14a6825

Please sign in to comment.