-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid relying on constructor name for
isGlimmerComponent
check (…
…#11) This fixes an issue with minified builds, where the name of the Glimmer component constructor may not be the same string used in development builds. The check now works without doing anything to check the name of the class, so that it'll work even when minified.
- Loading branch information
1 parent
9e74815
commit 75a14b0
Showing
3 changed files
with
42 additions
and
47 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
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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* global require */ | ||
|
||
// Import through `require` in case it is not a dependency | ||
const GlimmerComponentModule = require('@glimmer/component'); | ||
const GlimmerComponent = GlimmerComponentModule && GlimmerComponentModule.default; | ||
|
||
/** | ||
* Indicates whether a class is a Glimmer component. | ||
* | ||
* @param {Class} targetClass | ||
* @returns {Boolean} | ||
* @private | ||
*/ | ||
export function isGlimmerComponent(targetClass) { | ||
if (!GlimmerComponent) { | ||
return false; | ||
} | ||
|
||
let ancestor = targetClass; | ||
|
||
while (ancestor) { | ||
if (ancestor === GlimmerComponent) { | ||
return true; | ||
} | ||
|
||
ancestor = Object.getPrototypeOf(ancestor); | ||
} | ||
|
||
return false; | ||
} | ||
|