Skip to content

Commit

Permalink
fix rebase and address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Apr 22, 2021
1 parent 041b592 commit 2bd374f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import { setupTest } from 'ember-qunit';

import JSONAPIAdapter from '@ember-data/adapter/json-api';
import Model from '@ember-data/model';
import { RecordData, relationshipsFor, relationshipStateFor } from '@ember-data/record-data/-private';
import { relationshipsFor, relationshipStateFor } from '@ember-data/record-data/-private';
import JSONAPISerializer from '@ember-data/serializer/json-api';
import Store from '@ember-data/store';
import { identifierCacheFor, recordDataFor } from '@ember-data/store/-private';
import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in-debug';

const { attr: DSattr, hasMany: DShasMany, belongsTo: DSbelongsTo } = DS;
Expand Down
35 changes: 24 additions & 11 deletions packages/record-data/addon/-private/graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ export function graphFor(store: RecordDataStoreWrapper | Store): Graph {
return graph;
}

/**
* Graph acts as the cache for relationship data. It allows for
* us to ask about and update relationships for a given Identifier
* without requiring other objects for that Identifier to be
* instantiated (such as `InternalModel`, `RecordData` or a `Record`)
*
* This also allows for us to make more substantive changes to relationships
* with increasingly minor alterations to other portions of the internals
* over time.
*
* @internal
*/
export class Graph {
declare identifiers: Map<StableRecordIdentifier, Relationships>;
declare store: RecordDataStoreWrapper;
Expand Down Expand Up @@ -60,29 +72,30 @@ export class Graph {
/*
implicit relationships are relationships which have not been declared but the inverse side exists on
another record somewhere
For example if there was
For example if there was:
```app/models/comment.js
import Model, { attr } from '@ember-data/model';
export default Model.extend({
name: attr()
});
export default class Comment extends Model {
@attr text;
}
```
but there is also
and there is also:
```app/models/post.js
import Model, { attr, hasMany } from '@ember-data/model';
export default Model.extend({
name: attr(),
comments: hasMany('comment')
});
export default class Post extends Model {
@attr title;
@hasMany('comment') comments;
}
```
would have a implicit post relationship in order to be do things like remove ourselves from the post
when we are deleted
Then we would have a implicit 'post' relationship for the comment record in order
to be do things like remove the comment from the post if the comment were to be deleted.
*/
getImplicit(identifier: StableRecordIdentifier): RelationshipDict {
let relationships = this.implicitMap.get(identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ export default class BelongsToRelationship extends Relationship {

notifyBelongsToChange() {
let recordData = this.recordData;
let storeWrapper = this.store;
storeWrapper.notifyBelongsToChange(recordData.type, recordData.id, recordData.lid, this.key);
this.store.notifyBelongsToChange(recordData.type, recordData.id, recordData.lid, this.key);
}

removeCanonicalRecordDataFromOwn(recordData: StableRecordIdentifier, idx?: number) {
Expand Down

0 comments on commit 2bd374f

Please sign in to comment.