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 🙏

© 2025 – Pkg Stats / Ryan Hefner

wechat-redux2

v1.0.7

Published

wechat redux is wechat global state management. fully support the redux grammar

Readme

wechat-redux2

wechat redux is wechat global state management. fully support the redux grammar

快应用redux状态管理库,完全支持redux语法,便于项目redux迁移

usage 用法

npm install wechat-redux2 --save 或 cnpm install wechat-redux2 --save

新增API

createLocalStorage

// actions => 需要缓存的 action.type 名称,详细请看示例
createLocalStorage(actions)

initStorage

// store => redux 实例
initLocalStorage(store);

store.js

/***
 * 这里修改状态
 */

import { createStore, applyMiddleware, compose, createLocalStorage } from 'wechat-redux2';

import thunkMiddleware from 'redux-thunk';
// redux 怎么配置就怎么配置就完事
import rootReducer from './reducers/index.js';
import { createLogger } from 'redux-logger';
import actions from './storage/index.js';

const middlewares = [
  thunkMiddleware,
  createLogger(),
  createLocalStorage(actions)
];

const enhancer = compose(
  applyMiddleware(...middlewares),
  // other store enhancers if any
);

export default function configStore() {
  const store = createStore(rootReducer, enhancer);
  return store;
}

app.js

<script>
/**
 * framework app 应用引擎
 * 改造微信小程序生命周期,保证执行顺序
 */
import app from './packages/framework/app.js';
import router from './packages/router/index.js';
import regeneratorRuntime from './packages/framework/runtime.js';
import configStore from './store/index.js';
const store = configStore();
import { initStorage } from 'wechat-redux2';
import request from './packages/request/index.js';
import {getUserInfo} from './store/actions/user.js';
import rules from './rules';

app({
  store,
  // 这个生命周期经过改造之后已经可以在进入页面前做完所有操作了
  onCreate: async function (page) {
    
    await initStorage(store);

    const { user } = store.getState();

    // token
    if (user.token) request.bind({
      header: {
        token: user.token
      }
    });

    await store.dispatch(getUserInfo());

  }
})
</script>

页面模版使用与data保持一致,所有redux操作都会与视图的data对象做双向绑定 connect 请看示例

// pages/user/index.js
import regeneratorRuntime from '../../packages/framework/runtime.js';
import { connect } from 'wechat-redux2';

const store = connect(
  ({user}) => ({
    user: user.info
  }),
  dispatch: () => ({})
);

const config = {

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    setTimeout(() => {

      console.log(this.data.user,123);
    },2000);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
};

Page(store(config));