Skip to content

Commit

Permalink
Totally different fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav0 committed Dec 2, 2019
1 parent b596abb commit bbcbc2e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 36 deletions.
1 change: 1 addition & 0 deletions packages/model/addon/-private/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,7 @@ const ID_DESCRIPTOR = {
// the _internalModel guard exists, because some dev-only deprecation code
// (addListener via validatePropertyInjections) invokes toString before the
// object is real.
this._internalModel && get(this._internalModel, '_tag');
return this._internalModel && this._internalModel.id;
},
};
Expand Down
22 changes: 5 additions & 17 deletions packages/store/addon/-private/identifiers/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import normalizeModelName from '../system/normalize-model-name';
import isStableIdentifier, { markStableIdentifier, unmarkStableIdentifier } from './is-stable-identifier';
import isNonEmptyString from '../utils/is-non-empty-string';
import CoreStore from '../system/core-store';
import { tracked } from '@glimmer/tracking';
import { gte } from 'ember-compatibility-helpers';

/**
@module @ember-data/store
Expand Down Expand Up @@ -416,21 +414,11 @@ function makeStableRecordIdentifier(
bucket: string,
clientOriginated: boolean = false
): Readonly<StableRecordIdentifier> {
let recordIdentifier;
if (gte('3.13.0')) {
class CoreRecordIdentifier {
lid = lid;
@tracked id = id;
type = type;
}
recordIdentifier = new CoreRecordIdentifier();
} else {
recordIdentifier = {
lid,
id,
type,
};
}
let recordIdentifier = {
lid,
id,
type,
};
markStableIdentifier(recordIdentifier);

if (DEBUG) {
Expand Down
25 changes: 6 additions & 19 deletions packages/store/addon/-private/system/model/internal-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { default as EmberArray, A } from '@ember/array';
import { setOwner, getOwner } from '@ember/application';
import { assign } from '@ember/polyfills';
import { run } from '@ember/runloop';
import { tracked } from '@glimmer/tracking';
import RSVP, { Promise } from 'rsvp';
import Ember from 'ember';
import { DEBUG } from '@glimmer/env';
Expand Down Expand Up @@ -35,7 +34,6 @@ import CoreStore from '../core-store';
import coerceId from '../coerce-id';
import recordDataFor from '../record-data-for';
import { HAS_MODEL_PACKAGE } from '@ember-data/private-build-infra';
import { gte } from 'ember-compatibility-helpers';

type DefaultRecordData = import('@ember-data/record-data/-private').RecordData;
type RecordArray = InstanceType<typeof RecordArray>;
Expand All @@ -51,22 +49,6 @@ type PromiseManyArray = InstanceType<typeof import('@ember-data/model/-private')
@module @ember-data/store
*/

let _tracked = tracked;
// Stub tracked if not defined in Ember
if (!gte('3.13.0')) {
_tracked = function() {
return function(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
const originalMethod = descriptor.value;

descriptor.value = function() {
originalMethod.apply(this, arguments);
};

return descriptor;
};
};
}

// once the presentation logic is moved into the Model package we can make
// eliminate these lossy and redundant helpers
function relationshipsFor(instance: InternalModel): Relationships {
Expand Down Expand Up @@ -152,7 +134,9 @@ function extractPivotName(name) {
@class InternalModel
*/
export default class InternalModel {
@_tracked _id: string | null;
_id: string | null;
_tag: number;
_;
modelName: string;
clientId: string;
__recordData: RecordData | null;
Expand Down Expand Up @@ -189,6 +173,7 @@ export default class InternalModel {
_getModelPackage();
}
this._id = identifier.id;
this._tag = 0;
this.modelName = identifier.type;
this.clientId = identifier.lid;

Expand Down Expand Up @@ -233,6 +218,7 @@ export default class InternalModel {
if (value !== this._id) {
let newIdentifier = { type: this.identifier.type, lid: this.identifier.lid, id: value };
identifierCacheFor(this.store).updateRecordIdentifier(this.identifier, newIdentifier);
set(this, '_tag', this._tag + 1);
// TODO Show deprecation for private api
}
} else if (!IDENTIFIERS) {
Expand Down Expand Up @@ -1395,6 +1381,7 @@ export default class InternalModel {
let didChange = id !== this._id;

this._id = id;
set(this, '_tag', this._tag + 1);

if (didChange && id !== null) {
this.store.setRecordId(this.modelName, id, this.clientId);
Expand Down

0 comments on commit bbcbc2e

Please sign in to comment.