-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE set-component-template] Add @ember/component/template-only
As part of RFC 481 this adds the `@ember/component/template-only` module, and its associated implementation. Co-authored-by: Robert Jackson <me@rwjblue.com>
- Loading branch information
1 parent
b31998b
commit b53699e
Showing
7 changed files
with
119 additions
and
2 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 @@ | ||
export { Component } from '@ember/-internals/glimmer'; |
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,45 @@ | ||
// This is only exported for types, don't use this class directly | ||
export class TemplateOnlyComponent { | ||
constructor(public moduleName = '@ember/component/template-only') {} | ||
|
||
toString(): string { | ||
return this.moduleName; | ||
} | ||
} | ||
|
||
/** | ||
@module @ember/component/template-only | ||
@public | ||
*/ | ||
|
||
/** | ||
This utility function is used to declare a given component has no backing class. When the rendering engine detects this it | ||
is able to perform a number of optimizations. Templates that are associated with `templateOnly()` will be rendered _as is_ | ||
without adding a wrapping `<div>` (or any of the other element customization behaviors of [@ember/component](/ember/release/classes/Component)). | ||
Specifically, this means that the template will be rendered as "outer HTML". | ||
In general, this method will be used by build time tooling and would not be directly written in an application. However, | ||
at times it may be useful to use directly to leverage the "outer HTML" semantics mentioned above. For example, if an addon would like | ||
to use these semantics for its templates but cannot be certain it will only be consumed by applications that have enabled the | ||
`template-only-glimmer-components` optional feature. | ||
@example | ||
```js | ||
import templateOnly from '@ember/component/template-only'; | ||
export default templateOnly(); | ||
``` | ||
@public | ||
@method templateOnly | ||
@param {String} moduleName the module name that the template only component represents, this will be used for debugging purposes | ||
@category EMBER_GLIMMER_SET_COMPONENT_TEMPLATE | ||
*/ | ||
export default function templateOnlyComponent(moduleName: string): TemplateOnlyComponent { | ||
return new TemplateOnlyComponent(moduleName); | ||
} | ||
|
||
export function isTemplateOnlyComponent(component: unknown): component is TemplateOnlyComponent { | ||
return component instanceof TemplateOnlyComponent; | ||
} |
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