xiaoyao96 / wxministore Goto Github PK
View Code? Open in Web Editor NEW一个基于微信小程序的mini全局状态管理库
License: MIT License
一个基于微信小程序的mini全局状态管理库
License: MIT License
我将这个库 迁移到淘宝小程序了,目前测试 page之间用store是没问题 可以获得的,
page和组件之间通讯 目前有问题 ,希望可以 探讨下怎么适配到淘宝小程序 ,我已经加你微信,麻烦通过 下
我的wx:110837675
由于 onShareAppMessage 、 onReachBottom 、onPullDownRefresh等是触发性事件函数,所以不能归类为生命周期,也就是说,不能直接 pageListener[key].apply(this, arguments);对于触发性事件函数,我建议单独归类,同时采用赋值 o[key] = pageListener[key],但是有个前提就是 o[key]无效,才采用公用的。建议下个版本修改一下!
生命周期是直接执行,所以能够 pageListener[key].apply(this, arguments),触发事件不会直接执行,所以必须采用赋值,等到触发时执行!
就像这样:
store.setState({ data: data},()=>{});
复现场景
用户为第一次下载小程序,进入小程序直播分包内,app.js调用request.js请求
返回结果后使用getCurrentPages().pop()为空 拿不到store methods内的方法
app.js内onLaunch和onShow第一时间拿不到getCurrentPages().pop()内方法需要加延时
其他情况是可以拿到的 在非page和components内还有其他方法可以拿到methods方法么
有什么方法可以兼容一下么 还是我的打开方式不对😂
如题
希望在某个属性有变化的时候执行特定的方法,使用Object.defineProperty似乎不太可行。
最新稳定版本v1.02.1910120,在工具中插件无法正常使用
在手机端的时候,经常出现,app.store.setState后无法执行回调的情况。
在App.js的onLaunch中请求后台api获取用户信息,然后保存到store中
然后在首页onLoad中从store中获取用户信息,结果是空
我知道这是由于异步导致的,如何在页面中监听到store中有值了,然后获取值,并且渲染到页面中
你好,请问store.setState之后,刷新页面,getState()的值还是初始值呢?
跨组件数据状态变化监听怎么处理
是否可以实现在页面监听到state的修改,之后对数据进行修改/处理
建议加个可选的配置项控制是否显示调试信息。
这一点我觉得omix做的不错。
如果 pageListener 添加 onShareAppMessage 会调用这个方法没问题.但是 没效果
在App.js的onLaunch()中请求后端获取userInfo。然后要在首页index.js中监听到userInfo后,才能进行其它的业务,可是目前没这个功能啊,总不能用定时器去循环等待吧,太美中不足了,期待能早点更新数据监听
` /* store.js */
pageLisener: {
onShareAppMessage(ops) {
if (ops.from === "menu") {
console.log("ShareAppMessage menu")
return {
title: "自定义标题1",
path: "/pages/loading/loading",
imageUrl: "xxxx"
}
}
}
}
这样设置,真机和开发者工具上 title ,imageUrl 无效; 另外如果我在pageA页面扩展了onShareAppMessage
/* pageA.js */
onShareAppMessage(ops) {
if (ops.from === "button") {
console.log("ShareAppMessage button")
return {
title: "自定义标题2",
imageUrl: 'xxxxxx',
path: "/pages/pDetail/pDetail?xxxx"
}
}
console.log('share end')
}
`
当点击右上角的分享 (ops.from === "menu"),控制台依然会输出‘share end’,
当点击自定义的分享 (ops.from === "button"),控制台不会输出‘share end’,
且2种情况title,imageUrl 都无效
onThemeChange(Object object)
基础库 2.11.0 开始支持,低版本需做兼容处理。
系统切换主题时触发。也可以使用 wx.onThemeChange 绑定监听。
参数:与 wx.onThemeChange 一致
https://developers.weixin.qq.com/miniprogram/dev/reference/api/App.html#onThemeChange-Object-object
[2019.11.27] F
: 优化diff能力。
[2019.9.6] F
: 修复删除state中的数组,删除的项会为null的问题。
[2019.6.26] A
: 新增store.prototype.getState,用于读取store.$state的拷贝,防止对原状态进行误操作。
[2019.6.25] F
: 修复setState为引用类型数据时视图可能不会更新。
[2019.4.15] A
: 组件/页面内 新增useProp属性,指定当前组件/页面使用指定状态,提高性能。
[2019.4.15] U
: store.setState加入diff算法,更加高效。
[2019.4.2] F
: 修复pageLisener内部分周期执行时报错。
[2019.3.24] F
: 修复使用plugins插件时,提示non-writable错误。(解决方案)。
[2019.3.24] F
: 对Component中lifetimes字段的兼容。
[2019.3.21] F
:测试发现小程序原生的setData会默认深拷贝目标对象。所以导致了#3,目前已修复,也说明了setState后,各个页面的$state不再是完全引用的关系。
[2019.3.17] U
:不再支持es5,并重写源码(es6),代码更少,做的更多,又恢复了$state完全引用(仅首次加载),修复了一些极端情况的bug。
[2018.11.29] A
:新增局部状态模式, 可设置$state部分页面或组件可用,大幅提升性能。
[2018.11.16] A
:支持es5。
[2018.10.31] A
:拓展新增周期监听 pageLisener字段,可监听所有页面的所有生命周期事件。
[2018.10.30] A
:拓展新增功能全局方法 methods字段,大幅优化setState性能。更新前需调整Store结构,请阅读Store对象参数详情。
{
list: [1]
}
我删掉list里面的第一个,结果数据变成了
{
list:[null]
}
结果我的页面就显示了一个空的元素,能改一下这个bug吗
后期考虑适配一下支付宝小程序不
我在index页面使用是App.Page() 创建页面,页面加载不了直接空白了,怎么解决
请问怎样在mystore.js,method方法中修改state中的值,其他页面调用这个方法
app.store.setState({
msg: "我被修改了,呜呜..."
});
console.info(app.store.$state,'lee2');
如题~
像useStore属性,传一个数组为store.$state里的属性
例如 const store = new Store({a:1, b:2, c:3})
在Compoent({useProps: ['a']}), 这样这个页面的this.data.$state里就只挂载a属性
// store.js
let store = new Store({
state:{
token:"",
hasLogin:false,
},
methods:{
// 刷新token
refreshToken(token){
// ......
// 无法直接设置state中的token
},
}
})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.