Skip to content

Commit

Permalink
Refactor ember-data feature detection
Browse files Browse the repository at this point in the history
Instead of checking if DS exists, we now check if `Model` from `@ember-data/model` is present.
  • Loading branch information
fsmanuel committed Nov 8, 2023
1 parent 9b22790 commit 67c14b5
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions addon/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { isHTMLSafe } from '@ember/template';
import EmberObject from '@ember/object';
import { typeOf } from '@ember/utils';
import { A as emberArray } from '@ember/array';

// ember-data feature detection
import {
macroCondition,
dependencySatisfies,
Expand All @@ -17,6 +19,19 @@ if (macroCondition(dependencySatisfies('ember-data', '*'))) {
Model = importSync('@ember-data/model').default;
}

export function isDsModel(o) {
return !!(Model && o && o instanceof Model);
}

export function isDSManyArray(o) {
return !!(
DS &&
o &&
(o instanceof DS.PromiseManyArray || o instanceof DS.ManyArray)
);
}

// ember internals
export { getDependentKeys, isDescriptor } from '../-private/ember-internals';

export function unwrapString(s) {
Expand Down Expand Up @@ -45,18 +60,6 @@ export function isPromise(p) {
return !!(p && canInvoke(p, 'then'));
}

export function isDsModel(o) {
return !!(Model && o && o instanceof Model);
}

export function isDSManyArray(o) {
return !!(
DS &&
o &&
(o instanceof DS.PromiseManyArray || o instanceof DS.ManyArray)
);
}

export function isEmberObject(o) {
return !!(o && o instanceof EmberObject);
}
Expand Down

0 comments on commit 67c14b5

Please sign in to comment.