javascript - 使用 Reflux,资源是 2 家商店还是 1 家商店? (自行车/CurrentBike 与自行车)

标签 javascript reactjs reactjs-flux refluxjs

我仍在努力思考前端状态。是否有为资源设置商店的通用最佳实践?例如,我的 web api 有:

GET /bikes
GET /bikes/:id

我开始时只有一个 BikeStore 和 bikes: []。现在我正在处理 ShowBike 组件,不确定我是否应该使用 BikeStore(不确定如何使用)或为单个项目创建第二个商店。

最佳答案

Flux 中的存储概念是客户端如何访问数据的相当简单的抽象。应该为不同类型的数据使用单独的存储。在您的情况下,资源是相同的,没有任何充分的理由为自行车保留单独的商店。更重要的是:存储单个项目不是预期用途,应该避免。

来自助焊剂docs :

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 — they do not represent a single record of data like ORM models do. Nor are they the same as Backbone's collections. More than simply managing a collection of ORM-style objects, stores manage the application state for a particular domain within the application.

关于javascript - 使用 Reflux,资源是 2 家商店还是 1 家商店? (自行车/CurrentBike 与自行车),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29731522/

相关文章:

javascript - 在 React Native 中渲染 2 个列表

reactjs - 如何通过调用单个 onChange 函数将值插入状态 - react

javascript - 在组织 AngularJS 应用程序时,您的模块是否都应该具有相同的名称?

javascript - 三个 : PlaneGeometry load texture to specific faces

javascript - 淡出边框 (css)

reactjs - ReactCSSTransitionGroup 似乎没有应用动画

reactjs - React - 将数据映射到映射函数期间形成的行

javascript - 按标签名删除元素

javascript - React 组件未在 redux 状态更新时更新

reactjs - 带有 React 类型的 TypeScript 将无法编译