GemElement
class GemElement extends HTMLElement {
constructor(): GemElement;
// ...
}Module entry points
Gem provides separate entry points so you can choose which layer to use:
Use @mantou/gem/lib/element or @mantou/gem for Lit-backed html/svg templates and directives. The reactive entry does not initialize the Lit template engine.
Class Decorator
| name | description |
|---|---|
@customElement |
Class decorator, define custom elements tag |
@connectStore |
Class decorator, bound to Store, element auto update by Store update |
@adoptedStyle |
Class decorator, adopt style sheet |
@shadow |
Class decorator, Use ShadowDOM render content |
@light |
Class decorator, Use light dom render content, default |
@async |
Class decorator, Use no blocking render |
@aria |
Class decorator, Specify the accessibility info |
Field Decorator
| name | description |
|---|---|
@attribute |
Field decorator, defining string type reactivity Attribute |
@boolattribute |
Field decorator, defining boolean type reactivity Attribute |
@numattribute |
Field decorator, defining number type reactivity Attribute |
@property |
Field decorator, define reactivity Property, no default value |
@emitter |
Field decorator, define event emitter, similar to HTMLElement.click |
@globalemitter |
Similar @emitter, comes with composed and bubbles attributes |
@state |
Field decorator, define the inside of the element css state |
@slot |
Field(static or instance) decorator, slot that defines the element |
@part |
Field(static or instance) decorator, part that defines the element |
NOTE
All field decorators except
@propertyprovide a default value. Names defined by@attribute/@boolattribute/@numattribute/@state/@slot/@partare automatically converted to kebab-case; use the kebab-case names outside the element.
Type with decorator
| name | description |
|---|---|
Emitter<T> |
The type of the field defined by @emitter |
Method Decorator
| name | description |
|---|---|
@memo |
Similar GemElement.memo |
@effect |
Similar GemElement.effect |
@willMount |
Similar GemElement.willMount |
@mounted |
Similar GemElement.mounted |
@unmounted |
Similar GemElement.unmounted |
@template |
Similar GemElement.render + GemElement.shouldUpdate |
@fallback |
When the content render error, rendering the reserve content |
Deprecated lifecycle compatibility
These lifecycle methods remain for backward compatibility, but are deprecated and may be removed. Do not use them in new elements; use decorators instead.
| Legacy method | Use instead |
|---|---|
willMount |
@willMount() |
render |
@template() |
shouldUpdate |
The condition argument to @template((instance) => condition) |
mounted |
@mounted() |
updated |
@effect(); provide a dependency function when it should run only for specific changes |
unmounted |
@unmounted() or a cleanup function returned from @effect() |
Method
| name | description |
|---|---|
effect |
Register side effects, you can specify dependencies |
memo |
Register callback, you can specify dependencies |
update |
Update elements manually |
internals |
Get the element's ElementInternals object |
Utils
| name | description |
|---|---|
createRef |
Defining dom references |
createState |
Specify the element internal state |
css |
Use the constructor to create a style sheet that can be attached to the element |
html |
Template string tags, used to create HTML lit-html templates |
svg |
Template string tags, used to create SVG lit-html templates |
render |
Mount lit-html template to DOM |
directive |
Custom lit-html template rendering directive |
repeat |
Optimize lit-html list rendering directive |
NOTE
Import from
@mantou/gem/lib/reactivewhen you do not need the Lit template engine. If a component needs Lit-backed templates, use@mantou/gem/lib/elementinstead.
