我仍在努力思考前端状态。是否有为资源设置商店的通用最佳实践?例如,我的 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/