0.0.13 • Published 5 years ago

@mijizhe-opensource/store v0.0.13

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

@mijizhe-opensource/store

介绍

超轻量状态管理库

遇到问题,请提交issues,或者加 QQ 群278574710

软件架构

  1. 基于 Proxy 新特性的状态管理库,无外部类库依赖,轻量好用,五分钟掌握,可轻松用于小程序,web app 等项目。
  2. 使用 Typescript,JavaScript 亦可用

安装教程

npm i @mijizhe-opensource/store

使用说明

  1. 声明仓库
// ./store.js
import { State, Store } from "@mijizhe-opensource/store"
const rootState = new State({
  foo: "I'm foo",
  bar: new State({
    title: "I'm foobar",
  }),
})
export default new Store(rootState)
  1. 业务中使用
// ./updateDocumentTitleCase.js
import store from "./store.js"
const subscription = store.subscribe(
  store.SUBSCRIPTION_TYPE__STATE_UPDATED,
  (state, key, newValue, oldValue) => {
    // 这里可以做一些数据驱动的操作
    // 例如,当 rootState.bar.title 在其他地方发生修改时,页面标题设置成新值
    if (state === store.state.bar && key === "title") {
      document.title = newValue
    }
  }
)
// 不再需要订阅时,记得取消订阅
// subscription.unsubscribe()

// ./test.js
import store from "./store.js"
store.state.bar.title = "goooooooooooood"
// 此时,`./updateDocumentTitleCase.js` 代码所在页面标题发生了改变

API

  • store.subscribe(type: symbol, observer: Function): Object

AD

微信小程序开发时,很多场景特别需要类似 vue 的computedwatch等特性,为此,我们特推出了小程序敏捷开发库@mijizhe-opensource/well,再结合本状态管理库,让小程序开发飞起来

0.0.13

5 years ago

0.0.11

5 years ago

0.0.12

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.3

5 years ago

0.0.4

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago