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

@matrixage/moon

v1.1.0

Published

可能是世界上最小巧的小程序功能增强库

Downloads

12

Readme

moon

可能是世界上最小巧的小程序功能增强库.

install

  1. npm i @matrixage/moon

  2. 微信开发者工具 -> 工具 -> 构建npm

usage

moon (全局状态管理)

  1. 在app.js中定义全局变量
import { moon } from '@matrixage/moon'

App({
	onLaunch () {
		moon(wx).define({
            		userinfo:{},
			loaded: false
		})
	}
})
  1. 在A页面修改已经定义的值
wx.$set({
      loaded:true
})
  1. 在B页面监听字段的变化
wx.$watch('loaded',(new_val,old_val)=>{
      this.setData({
            visible_ads: new_val
      })

      console.log(old_val)
})

connect (支持dva model)

页面的js文件 (index.js)

import { connect } from require('@matrixage/moon')
import model from './model'

const page = {
	onLoad () {
		this.dispatch({
			type: 'showLoading'
		})
	}
}

connect(page, model)

页面的model文件 (model.js)

import { Service_getContent, Service_getUserinfo } from './services'

export default {
	data: {
		list: [],
		userinfo: {},
		loading: false
	},

	effects: {
		async query ({ payload }) {
			const { result, success } = await Service_getContent({ type: 1 })

			if (!success) return

			this.setData({
				list: result
			})
		},
		async getUserinfo () {
             const {result, success} = await Service_getUserinfo()
                  
            if (!success) return
                  
			this.setData({
				userinfo: result
			})
		}
	},

	reducers: {
		showLoading () {
			this.setData({ loading: true })
		},
		hideLoading () {
			this.setData({ loading: false })
		}
	}
}

在index.js中使用this.dispatch({type,payload})调用model.js中的函数,在model.js中直接使用this.setData({data})对数据进行变更。

index.html负责视图展现 (view),index.js负责页面逻辑 (controller),model.js负责数据逻辑 (model)。基于“0入侵”的原则,简化了dva的一些概念,尽可能地让经验较少的开发者也能体会到标准MVC编程的快乐。

modelExtend (扩展model)

import { modelExtend } from '@matrixage/modelExtend'
import model from 'path/to/public_model'

export default modelExtend(model,{
      ...
})

promisifyAll (Promise化wxapi )

  1. 在app.js onLaunch函数的第一行执行绑定
import { promisifyAll } from '@matrixage/moon'

App({
	onLaunch () {
		promisifyAll(wx, wx.$)
	}
})
  1. 在其他地方直接使用
try {
      await wx.$.requestPayment(data)
} catch ( e ) {
      wx.$messageInfo( '支付失败' )

      return
}

wx.$messageSuccess( '预约成功' )

//wx.$messageInfo和wx.$messageSuccess是项目中封装的方法

typescript使用

小程序使用typescript打包出来的文件有点问题,先暂时手动复制粘贴声明文件

declare namespace WechatMiniprogram {
      interface Wx {
            $: any
            $set: () => void
            $watch: () => void
            $getData: object
      }
}

interface IModel {
      data:object
      effects:object
      reducers:object
}

declare module '@matrixage/moon'{
      export const moon:(wx:any)=>void
      export const connect:(page:object,model:object)=>any
      export const modelExtend:(public_model:IModel,public_model:IModel)=>IModel
      export const promisifyAll:(wx:any,wx$:any)=>void
}

理念

moon将始终保持小而美,要保证使用moon不会对现有代码造成任何侵入式破坏.