Skip to content

Commit

Permalink
isKnown - info object can be undefined (#72)
Browse files Browse the repository at this point in the history
Add guard to prevent the evaluation of 'known' for linked relationships when the relationship key is not being checked
  • Loading branch information
richardfrosztega authored and danielspaniel committed Nov 12, 2019
1 parent a845068 commit fe9dc84
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion addon/model-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Model.reopen({
},

observeUnknownRelationshipLoaded(sender, key/*, value, rev*/) {
if (Tracker.trackingIsSetup(this)) {
if (Tracker.trackingIsSetup(this) && Tracker.isTracking(this, key)) {
let saved = Tracker.saveLoadedRelationship(this, key);
if (saved) {
this.removeObserver(key, this, 'observeUnknownRelationshipLoaded');
Expand Down
12 changes: 12 additions & 0 deletions addon/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ export default class Tracker {
return info;
}

/**
* Find whether this key is currently being tracked.
*
* @param {DS.Model} model
* @param {string} [key]
* @returns {boolean} true if this key is being tracked. false otherwise
*/
static isTracking(model, key) {
let info = (model.constructor.trackerKeys || {});
return !!info[key];
}

/**
* On the model you can set options like:
*
Expand Down

0 comments on commit fe9dc84

Please sign in to comment.