将 UI 数据存储在 Repository 而不是 SharedViewModel 中是最佳实践吗?

发布于 2025-01-17 07:21:20 字数 284 浏览 4 评论 0原文

假设我有 3 个屏幕(3 个片段),都有自己的表单输入字段,最后一个屏幕将显示之前收集的所有表单数据,因此这些表单数据需要在到达最后一个屏幕之前存储在某个地方。

而且这些表单数据不需要持久化,用户使用此功能时必须重新从头开始填写表单。

我应该将每个片段的数据存储到 SharedViewModel 还是 Repository 中?

它适用于两种解决方案,但我正在尝试遵循 mvvm + clean 架构,并且我正在考虑在这种情况下遵循的最佳实践是什么。

任何建议将不胜感激。

太感谢了

Let's say I have 3 screens (3 fragments) with its own form input fields and the last screen will display all form data that collected before so these form data need to be stored at somewhere before reaching the last screen.

And these form data no need to be persisted, users have to start from the beginning again to fill the form when coming to this feature.

Should I store this data from each fragment into SharedViewModel or Repository?.

It works on both solutions but I'm trying to follow mvvm + clean architecture and I'm thinking about what is the best practice to follow in this scenario.

Any suggestions would be greatly appreciated.

Thank you so much

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一曲琵琶半遮面シ 2025-01-24 07:21:20

我认为你可以使用 SharedViewModel 。在您的情况下使用存储库是不必要的。

I think you can use SharedViewModel. Using a repository in your case is unnecessary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文