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

ewx

v1.0.1

Published

ewx 是一个基于 wxml 扩展的小程序 html 模板。主要功能是扩展 wxml 的数据绑定(可以调用函数等),并和 mobx 结合,使用 mobx 作为状态管理。

Downloads

2

Readme

ewx 模板引擎

ewx 是一个基于 wxml 扩展的小程序 html 模板。主要功能是扩展 wxml 的数据绑定(可以调用函数等),并和 mobx 结合,使用 mobx 作为状态管理。

ewx 对 wxml 的扩展

  1. 函数调用
<view wx:if="{{ [1,2].includes(1) }}">{{"hello" + name}}</view>
  1. 事件绑定可以传递一个函数
<view wx:for="{{array}}" bindtap="{{ ()=> click(item) }}">
  {{index}}: {{item.message}}
</view>

ewx 对 js 层的扩展

使用类来声明页面和组件

// demo.js
import { WeApp, createComponent } from 'ewx'

@createComponent(require)
export class Demo extends WeApp {
  title = 'weapp'

  // 生命周期和其他微信的回调方法
  onLoad() {
    // Do some initialize when page load.
  }

  // 自定义方法
  handle() {
    this.title = 'hello'
  }
  
  getFullTitle() {
    return this.title + '-mobx'
  }
}
// demo.ewx -> 使用 .ewx, 而不是 .wxml
<view bindtap="handle">{{ title }}  {{ getFullTitle() }}</view>

在这个类中没有小程序的 data、setData。所有实例变量(例如 title)都是响应式的 模板里可以绑定实例的变量和方法,实例里数据的发生改变也会同步到视图层(wxml)。 响应式数据的 api 是由 mobx 提供的,因此在实例里面也可以引用全局的 mobx 数据,从而实现全局状态管理。

api 介绍

Component 声明

import { WeApp, createComponent, prop, watch } from 'ewx'

@createComponent(require)
export class Counter extends WeApp {
  static options = {}
  static externalClasses = {}
  
  @prop(String) myProp1 // properties 声明

  @watch('myProp1') // 监听属性变化,参考原生组件的 observers
  myProp1Change(){
      
  }


  // 生命周期函数
  attached() { }
  moved() { }
  detached() { }
  
  // 组件所在页面的生命周期函数
  show() { }
  hide() { }
  resize() { }
  
  // 自定义方法
  handle() {
  
  }
  
  myPropertyChange() {
  
  }
}

Component 的配置目前只支持 options, externalClasses, 这三个参数都是静态属性,跟实例没有直接关系的。

update

需要设置 setData 回调时改用 update api

this.update({ title: 'abc' }, ()=> {}) // 和 setData 类似,但是更新的目标是当前的 this

template

.ewx 声明 template 的标签时,内部的标签内容不支持 .ewx 的语法,只能采用原生的语法

.ewx 调用模版时的语法 <template is="item" data="{{ {text: 'forbar'} }}"/>.wxml 调用模版时的语法 <template is="item" data="{{text: 'forbar'}}"/> 不同

include

<include src="" /> 内部的 wxml 暂不支持.ewx 的语法