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 Oct 26, 2023
1 parent 5bc0401 commit 3ecd1eb
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 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 require from 'require';

function requireModule(module, exportName = 'default') {
Expand All @@ -14,7 +16,21 @@ function requireModule(module, exportName = 'default') {

const DS = requireModule('ember-data');
const Model = requireModule('@ember-data/model');
const { ManyArray, PromiseManyArray } = DS;

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

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

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

export function unwrapString(s) {
Expand Down Expand Up @@ -43,18 +59,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 3ecd1eb

Please sign in to comment.