Comments (23)
effect异步里返回的时候有处action ,我在想是不是这俩冲突了。因为我把在page里初始化时action移到effect里 就正常了。
from foca.
page A 点击按钮 执行model.effect 异步结果写入 state.info = abc ,同时点击按钮时弹出弹窗,弹窗里显示 state.info 。 弹窗初始的时候useEffect(()=>model.action)
这样就会出错了。得把model.action移到model.effect里面。 但这俩逻辑又不一样,放一起有点怪。
from foca.
出现action in action 一般是因为在action方法内部执行了其它action或者effect方法。我看下有没有遗漏的场景。你这边也看下有没有办法提供一个可复现的repo
from foca.
抱歉,我这里暂时没看出什么问题。
另外我发布了1.0.1
版本使得报错信息中能同时展示冲突的action和上次执行的action,建议你升级后再试一次
from foca.
抱歉,我这里暂时没看出什么问题。 另外我发布了
1.0.1
版本使得报错信息中能同时展示冲突的action和上次执行的action,建议你升级后再试一次
好的我先更新一下
from foca.
抱歉,我这里暂时没看出什么问题。 另外我发布了
1.0.1
版本使得报错信息中能同时展示冲突的action和上次执行的action,建议你升级后再试一次
错误提示是对的,model.effect 异步返回结果时调用action更新state, 和 在page里的useEffect里调用action初始某个state 发生冲突了。
from foca.
更新一个issus 以前没有提示的地方现在也有个提示了。就是在model.effect 异步结果里_this.action会提示不存在属性action。
from foca.
排查比较困难,能否提供一个可复现的简易repo?
from foca.
更新一个issus 以前没有提示的地方现在也有个提示了。就是在model.effect 异步结果里_this.action会提示不存在属性action。
effect不能使用箭头函数,以及异步回调需要使用箭头函数,才能保证this的正确性
from foca.
贴代码吧。也有可能是我写的有问题 见谅。
Taro 3.4.9 。
PageA.jsx
const btnClick = () => {
someModel.doEffect(params)
someModel.openModalAction(true)
}
<Modal open={model.open} />
SomeModel.js
effects: {
async getSomeApiInfo(cid) {
var _this = this;
await Taro.request({
method: 'POST',
url: 'https://url',
data:{
},
success(res) {
_this.setAction(res.data)
}
});
}
},
actions:{
setAction(state,val){
state.somekey=val
},
openModalAction(state,val){
state.open = val
},
setAnotherAction(state,val){
state.otherkey=val
}
}
Page Modal.js
//这里要初始一些modal页里的数据
useEffect(()=>{
someModel.setAnotherAction(val)
},[])
这样写的话,点击按钮modal出现的时候模拟器正常,手机上就会分发错误,但是如果把modal里useEffect里的移到 _this.setAction(res.data)这句后面 就没事了
from foca.
写法没有问题,建议先切换到0.12.3(功能一致),我本地再测试一下。
另外再提供一下测试手机的系统和版本
from foca.
ios 和 微信 都最新版本
from foca.
微信库是2.24.7
from foca.
node_modules/foca/dist/esm/index.js
第 476-483行的try-finally 代码替换成下面这段试试
try {
dispatching = true;
prevAction = action;
var result = dispatch2(action);
prevAction = null;
dispatching = false;
return result;
} catch (e) {
prevAction = null;
dispatching = false;
throw e;
}
我怀疑小程序不支持finally,但是没有证据,家里没办法真机调试
from foca.
好的 我现在试一下
from foca.
好的 我现在试一下
找到一篇之前看的文章,应该和这个问题类似:https://forum.cocos.org/t/ios-bug-jsc-await-promise-mircotasks/83275
我这边也复现了,同步执行的操作被插入了其它操作。
from foca.
我好像说错了action,但是情况一样,地图regionChange时执行一个action 把区域更新到model里,然后在地图界面useEffect(()=>{apiEffect},[newregion])
effect返回的api数据少 就没问题,如果多的话就会提示分发错误,提前这个effect里的action未完成
from foca.
大概找到原因了,redux更新完数据后,会遍历subscriber并执行,其中react-redux也订阅了,react-redux那边检测到数据变化然后执行了一下forceUpdate
,导致useEffect被提前处理。我估计taro升级到react@18之后,这个问题能自动修复
所以目前有两个方式:
- 去除action in action 的功能,因为本身也就是一个规范辅助。
- 花点时间重构一下
你那边暂时解决的思路可以这么做:
useEffect(() => {
Promise.resolve().then(() => {
model.action();
});
}, []);
from foca.
好,感谢
from foca.
已经发布 v1.0.2 解决了这个问题,如果没问题则关闭此issue
from foca.
加油
from foca.
晚点试一下
from foca.
nice job
from foca.
Related Issues (20)
- Cannot find namespace 'NodeJS' HOT 3
- tarojs/components 组件标红! HOT 9
- add support of undefined type in initialState HOT 4
- 如何在modelA里访问modelB的数据? HOT 4
- 一定要在 effects 中使用 this.setState 或者 先定义 actions 方法调用才能更新状态吗 HOT 6
- 关于持久化的版本号 HOT 7
- 多个loading的情况 HOT 1
- [New Feature]是不是可以增加一个即用即创建的功能 HOT 6
- [Improvement] reset的特性无需深拷贝 HOT 3
- [New Feature]响应式 支持对复杂对象的支持 HOT 2
- initialState参数很多,如何一次性setState更新? HOT 3
- actions,异步actions, reducer, methods, computed, watch 名称叫法 HOT 1
- 如何动态删除指定的缓存? HOT 1
- foca 2.0 规划
- 持久化没有把initvalue放进去 HOT 3
- onInit不会触发useLoading HOT 2
- taro 支付宝小程序不支持吗? HOT 9
- foca2 在低版本的手机有兼容问题,iphone6和部分oppo HOT 9
- 有办法删除Model吗? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from foca.