谁负责在带缓存的 Flux 应用程序中从服务器获取数据?

Who is responsible to fetch data from server in a flux app with caching?

在 flux webchat 示例应用程序和 README 图中,操作创建者似乎应该从服务器检索数据。

我看到的问题是,如果数据已经在存储中,则可能不需要提取。商店是唯一知道的,因此需要实际调度操作。

我认为最好尽可能获取非规范化数据,以尽量减少 xhr 调用。如果商店是非规范化的,例如MessageStore 将包含呈现消息所需的所有数据。每条消息看起来像

{
 "id": 42
 "message": "Héllo, you tried reactjs-flux too. Awesome isn't it!"
 "user": {id: 1337, username: "amirouche", bio: "maker"},
 "likes": [{id: 2600, username: "NinjaTurtle"}, {id: 2601, username: "Peer"}
}

商店可能有责任(通过事件?)用部分用户模型更新 UserStore。

我想到的另一种方法是拥有一些规范化的商店,并使用视图期望的模式创建特定的商店。

在这种情况下,在我看来,动作创建者只对分派有效负载有用,即。没用。

你怎么看?

我的商店通常处理获取数据。这样做可以确保所有逻辑都可以由商店本身管理,并且您可以完全控制 when/how/why 获取数据。

您还可以让商店相互通信,这也是为什么商店应该负责 handling/fetching 数据的另一个原因。

此外,正如 Flux 模式所描述的那样: "Stores contain the application state and logic. Their role is somewhat similar to a model in a traditional MVC, but they manage the state of many objects.." 让商店管理从 APIs/server-side.

获取数据确实有意义