Comments (3)
const initialState = {...};
type State = typeof initialState;
export const globalModel = defineModel('global', {
initialState,
effects: {
patchUpdate(data: Partial<State>) {
this.setState(data);
}
}
});
effects
里的setState支持部分数据更新,类似 React 的 setState
from foca.
谢谢 还有两个问题想请教下。
1、更细state时卡住了
const Screen: React.FC = () => {
const globalModel = useModel(GlobalModel);
// 这边是可以生效的,GlobalModel中的rememberPwdFlag更新了
const changeCheck = (isCheck: boolean) => {
GlobalModel.patchUpdate({ rememberPwdFlag: isCheck });
};
const { errors, touched, values, isValid, handleSubmit, setFieldValue, setFieldTouched } = useFormik<AuthForm>({
validateOnMount: true,
validationSchema: AuthValidation,
initialValues: { account: globalModel.account, password: globalModel.pwd },
onSubmit: async (values) => {
if (isValid) {
// 页面按钮点击了,会卡在这个地方,不会执行下去了
GlobalModel.patchUpdate({ account: values.account, pwd: values.password });
await GlobalModel.verifyPassword(values.account, values.password);
}
},
});
return (
<></>
);
};
export default LoginScreen;
2、modelA可以更新modelB的数据吗?
from foca.
-
看代码没有发现问题,可以看看控制台输出以及打印日志来排查。或者建一个最简单的repo方便我协助排查
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
- 使用时出现action in action的小问题 1.0.0 HOT 23
- 一定要在 effects 中使用 this.setState 或者 先定义 actions 方法调用才能更新状态吗 HOT 6
- 关于持久化的版本号 HOT 7
- 多个loading的情况 HOT 1
- [New Feature]是不是可以增加一个即用即创建的功能 HOT 6
- [Improvement] reset的特性无需深拷贝 HOT 3
- [New Feature]响应式 支持对复杂对象的支持 HOT 2
- 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.