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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mould.js

v1.0.6

Published

### 简介

Downloads

6

Readme

mould.js

简介

mould.js 主要为了解决不同标准元件在同一个平台公用的问题,并提供相应可方便对接的标准接口,让不同标准的元件可用类似的方法接入。

分层

UI结构树

用来描述 UI 编排的结构,本质上是一个对象树,可用各种方案生成

declare class Element {
  tagname: String, // 标签名
  content?: String, // 当 tagname 为 text 时的内容
  children: Array<Element>, // 子元素
  props: Object, // 属性
  key?: String | Number // key,类同 React 的 key
}

已知有几种可能性来生成 UI 结构树:

Origin

Origin 用以储存原元件的状态,方法等,可以当是一个桩,用于后面的过程

mould.js 提供了 create 方法方便创建 Origin 并将其转成对应的 Component,目前 Componennt 即 React Componennt,但从实现来讲可以替换成 Vue Component 等

import { create } from 'mould.js'

/**
 * @return Class extends Super
 */
create('my-component', { /* prototype */ }, { /* static properties */ }, /* Super Class, default is Seed */)
Seed

目前 Seed 源码如下,可以窥见其目前只有两个基本能力:

  • prepare 创建后做一些准备
  • render 渲染
function Seed() {
  // prepare some context
  if (this.prepare) this.prepare()
}
// state, props, children
Seed.prototype.render = function render(state, props, children) {
  return this.tpl(state, props, children)
}

export default Seed

所有 Origin 应为 Seed 的子孙类型

transform & createElement

对任何 tagname,我们都有对应的两个阶段:

  • transform(将 Origin 转成 Component)
  • createElement(将 Component 在目前底层体系生成实例,例如在 React 体系等同于调用 React.createElement)

默认状态下,transform 会将 UI 结构树转成 Component,但我们可以通过自定义路由的方式来让不同的 tagname 以不同的方式展示

resolve

resolve 是用来定义在不同条件下的 transform 和 createElement 过程的。

Interface ResolveConfig {
  match: String | RegExp | Function, // 匹配规则
  transform: (O: Origin) => C: Componennt, // 将对应 Origin 转成 Componennt 的方法
  createElement: (C: Componennt, props: Object, ...children: Array<Component>) => element: Element // 将 Component 生成 Element 实例的方法
}

resolve(resolveConfig: ResolveConfig)

例子

启动例子

npm install npm install webpack-dev-server -g webpack-dev-server

  • json.html - 结构树生成 Component
  • default.html - 默认的 Component 引用
  • react.html - 使用 React 组件的例子
  • third.html - 使用第三方组件(例如jQuery)的例子
  • plugin.html - 可扩展成插件机制演示
  • flux.html - 和 flux 结合的例子,可以做到根据不同路由对不同组件体系对接 flux