hsh-event-store
v1.0.3
Published
event store
Downloads
2
Maintainers
Readme
hsh-event-store
一个基于事件的全局状态管理工具。
如何使用
1、npm安装依赖
npm install hsh-event-store
2、数据共享(event-store)
const { HSHEventStore } = require("hsh-event-store")
const axios = require('axios')
const store = new HYEventStore({
state: {
name: "hsh",
age: 18
},
actions: {
getData(ctx) {
return new Promise((resolve,reject)=>{
setTimeout(()=>{
const res = {message: 'success', data: 'james'}
resolve(res)
ctx.name = res.data
},3000)
})
}
}
})
// 数据监听
store.onState("name", (value) => {
console.log("监听name:", value)
})
// 数据变化
setTimeout(() => {
eventStore.setState("name", "lilei")
}, 1000);
eventStore.dispatch("getData").then((res=>{
console.log(res)
}))