-
Notifications
You must be signed in to change notification settings - Fork 0
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 #90 from smile-io/fix-is-component-definition-helper
Fix is component helper issue
- Loading branch information
Showing
1 changed file
with
28 additions
and
14 deletions.
There are no files selected for viewing
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,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)); |