npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ebuilder

v0.0.2

Published

用react思维去开发webcomponent

Readme

Ebuilder

用react思维去开发webcomponent

兼容性

提供一个polyfill文件,对低版本做兼容。

浏览器 | 版本 | 支持 ---- | ---- | ---- Safari | 5.1.7+ | √ Internet Explorer | 11+ | √ Chrome | 54+ | √

Ebuilder 能做什么?

  • 进入js组件库,编辑html标签即可完成一个页面
  • 用生命周期钩子和状态器管理组件(但需要自己手动修改dom)
  • 组件基类是DOM,可以直接被vue\react等其他框架调用

创建一个简单应用

git clone https://github.com/kimchen003/ebuilder-quick-start.git
yarn install
yarn start

使用手册

  • componentWillMount:组件被安装前,被调用。
// 例如可以在组件被安装前调数据接口
componentWillMount() {
    this.getData()
        .then(result => {
            this.setState({ data: result });
        });
}
  • render:首次渲染时,被调用。
// 在渲染时定义组件初始结构
render() {
    return html`
        <div>Hello World !</div>
    `
}
  • componentDidMount:组件被安装后,被调用。
// 例如可以在组件安装后绑定事件
componentDidMount() {
    this.refs.btn.onclick = function(){
        ...
    }
}
  • update: 组件更新时,被调用。
// 例如可以在被点击是显示组件
update(change) {
    this.setState({ show: change.show });
}
  • componentDidUnmount: 组件被移除后,被调用。
// 例如可以在组件被移除后清除计时器
componentDidUnmount() {
    clearInterval(timer);
}

setState是组件统一的API,用于主动触发组件的样式或结构变化。
注:开发者需要手动控制state改变后的变化。

import { WebComponent, html, render } from 'ebuilder';

export default class EbuilderTest extends WebComponent {

    constructor() {
        super();

        this.state = {
            show : false
        };

    }

    render() {
        return html`
            <div>Hello World !</div>
        `;
    }

    update(change): void {
        if( change.show ){
            this.style.display = "block"
        }
    }


}

customElements.define("ebuilder-test", EbuilderTest );

ebuider会根据节点上的ref标记缓存节点
注:同一个标记只缓存一个节点

import { WebComponent, html, render } from 'ebuilder';

export default class EbuilderTest extends WebComponent {

    render() {
        const { Style } = this;
        this.className = Style.main;

        return html`
            <div ref='title'>Hello World !</div>
        `;
    }

    componentDidMount() {
        setTimeout(()=>{
            this.refs.title.innerHTML = 'Changed !';
        },300)
    }

}

customElements.define("ebuilder-test", EbuilderTest );

每次调用props,ebuilder会遍历组件标签上的attribute,然后返回一个json对象。同时把对每个属性值尝试进行JSON.parse(),并将属性名aa-bb转成aaBb格式。

<ebuilder-test goods-list="[{name:'香蕉'},{a:'苹果'}]"></ebuilder-test>
import { WebComponent, html, render } from 'ebuilder';

export default class EbuilderTest extends WebComponent {

    constructor() {
        super();

        this.state = {
            data : this.props['goodsList']
        };

    }

    render() {
        return html`
            ${
                data.map(c => {
                    return html`
                        <div>产品:${ c.a }</div>
                    `;
                })
            }
        `;
    }
}

customElements.define("ebuilder-test", EbuilderTest );

建议采用动态加载,压缩后的js文件在目录./polyfill/dist

<script>
    if( !window.customElements ){
        document.write('<script src="https://raw.githubusercontent.com/kimchen003/ebuilder/master/polyfill/dist/index.js"><\/script>');
    }
</script>