simplefeel / micro-reaction-miniprogram

one small ande strong state manage for miniprogram

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

micro-reaction-miniprogram

one small ande strong state manage for miniprogram

Install

npm install micro-reaction-miniprogram

Usage

1 create global store

import { createStore, observable } from "micro-reaction-miniprogram"

const store = observable({
  credits: {
    count: 0
  }
});

export default createStore('home', store)

2 connect page with store

import homeStore from "../../store"

import { mapToData } from "micro-reaction-miniprogram"

const connect = mapToData((store) => ({ count: store.credits.count }), 'home')


Page(connect({}))

3 chanage store, page auto reaction

<button class="btn" type="primary" bindtap="onTap">Add</button>
Page(connect({
  onTap(e) {
    homeStore.credits.count++
  },
  onJump(e) {
    wx.navigateTo({
      url: "/pages/mine/mine"
    })
  }
}))

Demo

see gif demo

About

one small ande strong state manage for miniprogram

License:MIT License


Languages

Language:JavaScript 100.0%