SkateJSWeb 组件规范功能抽象
SkateJS 是一个 Web 组件库,旨在提供扩充 Web 组件规范能力,它重点关注功能渲染管道、清理 attribute/property 语义和较小的占用空间。
抽象能力包括:
-
生成跨框架兼容组件。
-
通过 props 或原生类型,抽象出常见的 attribute/property 语义,例如属性 reflection 和 coercion。
-
添加一些生命周期回调以响应 prop 更新、渲染,以及管理内部组件状态的方法。
-
提供一组基本的 mixin,它们 hook 渲染器,如 @skatejs/renderer-preact。
使用 Skate 与 Preact 可以这样写 Web 组件:
// @jsx h
import { props, withComponent } from 'skatejs';
import withPreact from '@skatejs/renderer-preact';
import { h } from 'preact';
class WithPreact extends withComponent(withPreact()) {
static get props() {
return {
name: props.string // String could be used also to define the prop type
};
}
render({ name }) {
return <span>Hello, {name}!</span>;
}
}
customElements.define('with-preact', WithPreact);评论
