Skip to content

Commit

Permalink
Fix is component helper issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vladucu committed Jul 12, 2024
1 parent d532a7c commit 033dc73
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions addon/helpers/is-component-definition.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import { helper } from '@ember/component/helper';
import runtime from '@glimmer/runtime';
import * as glimmerRuntime from '@glimmer/runtime';

let { isCurriedComponentDefinition, CurriedValue } = runtime;
/**
* Checks if a value is a curried component definition.
*
* Example: value={{component ...}}
*/
const isCurriedComponentDefinition = function (value) {
return value instanceof glimmerRuntime.CurriedValue;
};

// TODO look into getting rid of this concept
export function isComponentDefinition(content) {
// Older embers have isCurriedComponentDefinition, new ones have CurriedValue
// and instanceof CurriedValue seems good enough.
// NOTE This is just copy/pasta from @embroider/util
// https://github.com/embroider-build/embroider/blob/main/packages/util/addon/ember-private-api.js#L21C1-L34C2
if (!isCurriedComponentDefinition) {
isCurriedComponentDefinition = function (content) {
return content instanceof CurriedValue;
};
const isComponentClass = function (value) {
return (
// If it's a Glimmer component class
typeof value === 'function' ||
// If it's a template-only component class
value instanceof glimmerRuntime.TemplateOnlyComponent
);
};

export function isComponent(value) {
if (typeof value === 'string' || value == null) {
return false;
}

if (isCurriedComponentDefinition(value)) {
return true;
}
return isCurriedComponentDefinition(content);

return isComponentClass(value);
}

export default helper(([content]) => isComponentDefinition(content));
export default helper(([content]) => isComponent(content));

0 comments on commit 033dc73

Please sign in to comment.