Skip to content

Commit

Permalink
Merge pull request #1404 from gitKrystan/fix-is-component
Browse files Browse the repository at this point in the history
  • Loading branch information
MelSumner authored Jun 6, 2023
2 parents 8d14052 + 3734a1b commit 92392b1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 26 deletions.

This file was deleted.

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;
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function render(
let OutletTemplate = lookupOutletTemplate(owner);
let ownerToRenderFrom = options?.owner || owner;

if (isComponent(templateOrComponent, owner)) {
if (isComponent(templateOrComponent)) {
// We use this to track when `render` is used with a component so that we can throw an
// assertion if `this.{set,setProperty} is used in the same test
ComponentRenderMap.set(context, true);
Expand Down

0 comments on commit 92392b1

Please sign in to comment.