Skip to content

Commit

Permalink
Remove DS import in utils
Browse files Browse the repository at this point in the history
We now depend on `@ember-data/model/-private` for `ManyArray` and `PromiseManyArray` and do the ember-data feature detection by checking if `Model` from `@ember-data/model` is present.
  • Loading branch information
fsmanuel committed Oct 26, 2023
1 parent 5bc0401 commit 6f4d32d
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 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 @@ -12,9 +14,24 @@ function requireModule(module, exportName = 'default') {
}
}

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

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 +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 6f4d32d

Please sign in to comment.