-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
chore: cleanup Implicit relationships #7463
Conversation
Asset Size Report for 257e4cd IE11 Builds EmberData shrank by 229.0 B (-38.0 B compressed)WarningsThe uncompressed size of the package @ember-data/model has increased by 976.0 B. Changeset
Full Asset Analysis (IE11)
Modern Builds EmberData shrank by 229.0 B (-38.0 B compressed)WarningsThe uncompressed size of the package @ember-data/model has increased by 976.0 B. Changeset
Full Asset Analysis (Modern)
Modern Builds (No Rollup) EmberData shrank by 428.0 B (-67.0 B compressed)WarningsThe uncompressed size of the package @ember-data/record-data has increased by 99.0 B. Changeset
Full Asset Analysis (Modern)
|
@@ -362,14 +375,21 @@ export default class Relationship { | |||
if (!this._hasSupportForImplicitRelationships(recordData)) { | |||
return; | |||
} | |||
let relationships = recordData._implicitRelationships; | |||
let relationship = relationships[this.inverseKeyForImplicit]; | |||
const relationships = implicitRelationshipsFor(recordData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let
if we are following our current style
@@ -516,7 +538,7 @@ export default class Relationship { | |||
const id = guidFor(inverseRecordData); | |||
|
|||
if (this._hasSupportForImplicitRelationships(inverseRecordData) && seen[id] === undefined) { | |||
const relationship = implicitRelationshipStateFor(inverseRecordData, this.inverseKeyForImplicit); | |||
const relationship = implicitRelationshipStateFor(inverseRecordData, this.inverseKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let
if (definition.inverseIsAsync !== undefined) { | ||
return !!definition.inverseIsAsync; | ||
} else { | ||
if (((definition as unknown) as { inverseIsAsync?: boolean }).inverseIsAsync !== undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats up with multiple casts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even though RelationshipDefinition implements RelationshipMeta typescript does not allow us to recast to it without first casting to unknown
unless we change the return type of relationshipsDefinitionFor
to be a union type. Since this is the only location that we leak our current implementation detail for meta on @ember-data/model it seemed better to leave the return type there alone.
kind: 'belongsTo' | 'hasMany'; | ||
type: string; | ||
key: string; | ||
type: string; // related type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
improves our typing throughout which allows us to drop some checks and extra initializations, makes where/when we are operating on an implicit relationship more clear (by using a flag instead of juggling keys). This allows us to have a single inverse key vs an inverseKey and inverseKeyForImplicit.
Only behavior change is that implicit keys are improved: before we were setting them to
undefined${this.key}
at all times, which is the reason for the (single) test change.Motivation is to more closely align the current state with my next PR so that these somewhat more cosmetic changes are more easily distinguished from the logical changes.