Skip to content

Commit

Permalink
getWithDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Sep 25, 2020
1 parent 06ea10d commit cf641c2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/model/addon/-private/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ function getRecordMeta(record) {
return meta;
}

function getWithDefault(meta, prop, value) {
if (meta[prop] === undefined) {
meta[prop] = value;
}
return get(meta, prop);
}

const retrieveFromCurrentState = computedMacroWithOptionalParams(function retrieveState() {
return computed('currentState', function(key) {
return this._internalModel.currentState[key];
Expand Down Expand Up @@ -404,7 +411,7 @@ class Model extends EmberObject.extend(DeprecatedEvented) {
}
}
let meta = getRecordMeta(this);
return get(meta, 'isError') || false;
return getWithDefault(meta, 'isError', false);
}
set isError(v) {
if (REQUEST_SERVICE && DEBUG) {
Expand Down Expand Up @@ -608,7 +615,7 @@ class Model extends EmberObject.extend(DeprecatedEvented) {
return request.state === 'rejected' && request.response.data;
}
let meta = getRecordMeta(this);
return get(meta, 'adapterError') || null;
return getWithDefault(meta, 'adapterError', null);
}
set adapterError(v) {
if (REQUEST_SERVICE && DEBUG) {
Expand Down

0 comments on commit cf641c2

Please sign in to comment.