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

swx-tcff

v0.0.6

Published

miniprogram npm

Downloads

5

Readme

微信小程序redux库 swx-tcff

注意:本库会用到regeneratorRuntime,需安装开发者工具最新版,开启“增强编译”

支持redux

  1. 初始化app
import { tcff } from 'swx-tcff'
// 创建app
const app = tcff.getApp()

app.use({
  // 基于swx-request实现的service
  api: apiMap,
  hooks: {
    error(e) {
      // 处理异常
      console.error(e)
    }
  }
})
// 加载model
app.use(appModel)

// 启动app
app.start()


App({
  ...app,

  onLaunch() {
    app.store.dispatch({ type: 'app/init' })
  },
  onShow(res) {
    app.store.dispatch({ type: 'app/change', payload: { showInfo: res } })
  }
})
  1. apiMap范例
export default {
  login: 'post userLogin',
}
  1. model范例 默认action
  • change 普通更新
  • replace 整个替换
  • reset 重置
  • patch 列表补丁更新 payload: { key, data, compare }
// model.js
// 本库会用到regeneratorRuntime,需安装开发者工具最新版,开启“增强编译”
import { swx } from 'swx-util'

export default {
  namespace: 'app',
  state: {
    isReady: false
  },
  flows:{
    * login(_, { call, put, callAction }) {
      // 登录
      const { code } = yield call(swx.login)
      yield put({ type: 'change', payload: { code } })
      // 获取用户信息
      const { authSetting } = yield call(swx.getSetting)
      if (authSetting['scope.userInfo']) {
        const { userInfo, encryptedData, iv } = yield call(swx.getUserInfo, { lang: 'zh_CN' })
        yield put({ type: 'change', payload: { userInfo, encryptedData, iv } })
        yield callAction({ type: 'loginService' })
      } else {
        // 未授权
        yield put({ type: 'change', payload: { authUserInfo: false } })
      }
    },
    * loginService(_, { call, put, select, context: { service } }) {
      const { code, encryptedData, iv } = yield select(state => state.app)
      const { success, data } = yield call(service.login, {
        JsCode: code,
        EncryptedData: encryptedData,
        Iv: iv
      })
      if (success) {
        yield put({ type: 'change', payload: { openId: data.OpenId, unionId: data.UnionId } })
      } else {
        yield put({ type: 'change', payload: { loginError: JSON.stringify(data) } })
        console.error(data)
      }
      yield put({ type: 'change', payload: { isReady: true } })
    }
  }
  1. Page范例
// page.js
import { Page } from 'swx-tcff'
import model, { namespace } from './model'

Page(model, state => ({
  ...state.app, ...state[namespace]
}), {
  onLoad(){
   this.dispatch({ type: `${namespace}/init` })
  },
  // model中的state更新时执行
  onStateChange(prevState) {
    const { loading } = this.data
    if(prevState.loading !== loading){}
  }
})

// model.js
export default {
  namespace: 'userOrder',
  state: {
    loading: false
  },
  flows:{
    * init(_, { call, put, callAction }) {
        // ...
    }
  }
}

其他

小程序专用库,详情参考npm构建文档

注意:

  1. 不需要babel编译
  2. "miniprogram": "src" 专用目录
  3. 模块路径必须写全,比如:'./wxapi/index',index不能省略