如何为具有列表/详细信息视图和分页的应用程序选择Redux状态形状? [英] How to choose the Redux state shape for an app with list/detail views and pagination?

查看:81
本文介绍了如何为具有列表/详细信息视图和分页的应用程序选择Redux状态形状?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,我的数据库中有很多条目(例如用户)。我还有两个路由,一个用于列表,另一个用于详细信息(您可以在其中编辑条目)。现在我正在努力解决如何处理数据结构问题。

Imagine I have a number of entries(say, users) in my database. I also have two routes, one for list, other for detail(where you can edit the entry). Now I'm struggling with how to approach the data structure.

我正在考虑两种方法和两种方法的组合。

I'm thinking of two approaches and a kinda combination of both.


  • 我导航到 / list ,我的所有用户都是从存储在redux中的api下载的存储,在用户键下,我还添加了某种 users_offset users_limit 只呈现部分列表

  • 然后我导航到 / detail /< id> ,并使用< id> 存储 current_selected_user 作为val ...这意味着我将能够获得我的用户这样的数据 users.find(res => res.id === current_selected_user)

  • 更新会很好也很容易,因为我只使用一个数据集和指向它的细节

  • 添加新用户也很简单,再次只使用相同的用户列表

  • I navigate to /list, all of my users are downloaded from api a stored in redux store, under the key users, I also add some sort of users_offset and users_limit to render only part of the of the list
  • I then navigate to /detail/<id>, and store currently_selected_user with <id> as the val... which means I will be able to get my user's data with something like this users.find(res => res.id === currently_selected_user)
  • updating will be nice and easy as well, since I'm working with just one data set and detail pointing to it
  • adding a new user also easy, again just working with the same list of users

现在我用这种方法遇到的问题是,wh用户列表变得庞大(比如数百万),下载可能需要一段时间。而且,当我直接导航到 / detail /< id> 时,我还没有下载所有用户,所以要获取我的数据需要,我要先下载整件事。数百万用户只需编辑一个。

Now the problem I have with this approach is that, when the list of users gets huge(say millions), it might take a while to download. And also, when I navigate directly to /detail/<id>, I won't yet have all of my users downloaded, so to get data for just the one I need, I'm gonna have to first download the whole thing. Millions of users just to edit one.


  • 我导航到 / list ,而不是从api下载我的所有用户,我只下载了几个,取决于我的 users_per_page users_current_page 将被设置为,我可能会将数据存储为 users_currently_visible

  • 然后我导航到 / detail /< id> ,使用<存储 curre_selected_user code>< id> 作为val ...而不是搜索 users_currently_visible 我只是从api下载用户的数据。

  • 更新时,我不会以任何方式更新 users_currently_visible

  • 也不会我在添加

  • I navigate to /list, and instead of downloading all of my users from api, I only download a couple of them, depending on what my users_per_page and users_current_page would be set to, and I'd probably store the data as users_currently_visible
  • I then navigate to /detail/<id>, store currently_selected_user with <id> as the val...and instead of searching through users_currently_visible I simply download user's data from api..
  • on update, I'm not gonna update users_currently_visible in any way
  • nor will I on add

我认为这里可能存在的问题是,我必须在访问时/ list ,再次从api下载数据,因为它可能与我的内容不同步在数据库中,我也可能不必要地详细下载用户数据,因为它们可能偶然已经在我的 users_currently_visible

What I see as possible problem here is that I'm gonna have to, upon visiting /list, download data from api again, because it might not be in sync with what's in the database, I also might be unnecessarily downloading users data in detail, because they might be incidentally already inside my users_currently_visible

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆