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

wechat-mini-program-decorator

v1.0.1

Published

wei xin mini program decorator

Downloads

4

Readme

修改page与component 原生写法,修改为class方式加注解@,并都添加了watch与compute

页面class js写法(json、wxml、wxss使用不变)

@Paged // 页面装饰器,替代Page({……写法
export default PageName extends BasePage {

    //此处若无操作可以省略构造方法
    constructor() {
        super();
        this.data = {
            dataKey: "dataValue",
            ...this.data
        }
    }

    //data除了写到constructor,也可以直接写到此处
    data = {

    }
    
    @Compute // 计算返回值, wxml 中使用: xxxx="{{computeKey}}"
    computeKey() {
        ……
        return result;
    }

    @Watch // data 中 watchKey 修改时回调
    watchKey() {
        ……
        do sth or this.setData({……});
    }

    // 生命周期函数
    onLoad() {

    }
    ……其他生命周期函数

    //普通方法直接写到此处,不能与生命周期函数同名
    myFunction() {
        ……
        //触发watch与compute
        this.setData({……})
        ……
    }
    
    ……
}

组件class js写法(json、wxml、wxss使用不变)

// 组件装饰器,替代Component({……写法
// properties 可直接写在装饰器中,优先级最高
@Componented({
    //组件properties
    properties: {
        propKey1: "propValue1",
        propKey2: "propValue2",
    }
}) 
export default ComponentName extends BaseComponent {

    //此处若无操作可以省略构造方法
    constructor() {
        super();
        this.data = {
            dataKey: "dataValue",
            ...this.data
        }
        //properties 也可写在此处
        this.properties = {
            propKey: "propValue",
            ...this.properties
        }
    }

    //data除了写到constructor,也可以直接写到此处
    data = {
        ……
    }
    
    //properties 也可写在此处
    properties = {
        ……
    }

    @Compute // 计算返回值, wxml 中使用: xxxx="{{computeKey}}"
    computeKey() {
        ……
        return result;
    }

    @Watch // data 或 properties 中 watchKey 修改时回调
    watchKey() {
        ……
        do sth or this.setData({……});
    }

    // 生命周期函数会自动识别并加入到lifetimes,同样适用于pageLifetimes
    ready() {

    }
    ……其他生命周期函数

    // 此写法也一样可用,优先级比直接写高
    lifetimes = {
        ……
    }
    
    // 此写法也一样可用,优先级比直接写高
    pageLifetimes = {
        ……
    }

    //普通方法直接写到此处,不能与生命周期函数同名
    myFunction() {
        ……
        // 触发watch与compute
        this.setData({……})
        ……
    }
    
    ……

}

BasePage为抽离的基础页面class,如无也可以不用继承

class BasePage {

  constructor() {
     ……
  }
    
  //子类相同方法若需要调用基类,只需 super.onLoad即可,其他方法同样
  onLoad(options) {
      ……
  };

  ……
    
}

BaseComponent为抽离的基础组件class,如无也可以不用继承

class BaseComponent {

  constructor() {
     ……
  }
    
  //子类相同方法若需要调用基类,只需 super.ready即可,其他方法同样
  ready() {
      ……
  };

  ……
    
}