-
-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1404 from gitKrystan/fix-is-component
- Loading branch information
Showing
3 changed files
with
4 additions
and
26 deletions.
There are no files selected for viewing
3 changes: 0 additions & 3 deletions
3
addon/addon-test-support/@ember/test-helpers/-internal/get-component-manager.ts
This file was deleted.
Oops, something went wrong.
25 changes: 3 additions & 22 deletions
25
addon/addon-test-support/@ember/test-helpers/-internal/is-component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,16 @@ | ||
import type { ComponentLike } from '@glint/template'; | ||
|
||
import getComponentManager from './get-component-manager'; | ||
import { getInternalComponentManager as getComponentManager } from '@glimmer/manager'; | ||
|
||
/** | ||
* We should ultimately get a new API from @glimmer/runtime that provides this functionality | ||
* (see https://github.com/emberjs/rfcs/pull/785 for more info). | ||
* @private | ||
* @param {Object} maybeComponent The thing you think might be a component | ||
* @param {Object} owner Owner, we need this for old versions of getComponentManager | ||
* @returns {boolean} True if it's a component, false if not | ||
*/ | ||
function isComponent( | ||
maybeComponent: object, | ||
owner: object | ||
): maybeComponent is ComponentLike { | ||
// SAFETY: in more recent versions of @glimmer/manager, | ||
// this throws an error when maybeComponent does not have | ||
// an associated manager. | ||
try { | ||
return !!getComponentManager(maybeComponent, owner); | ||
} catch (e) { | ||
if ( | ||
`${e}`.includes( | ||
`wasn't a component manager associated with the definition` | ||
) | ||
) { | ||
return false; | ||
} | ||
|
||
throw e; | ||
} | ||
function isComponent(maybeComponent: object): maybeComponent is ComponentLike { | ||
return !!getComponentManager(maybeComponent, true); | ||
} | ||
|
||
export default isComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters