使用 Reflux,资源是 2 家商店还是 1 家商店? (Bikes/CurrentBike 对比自行车)
With Reflux, 2 stores or 1 store for a resource? (Bikes/CurrentBike vs Bikes)
我仍在努力思考前端状态。是否有为资源设置商店的通用最佳实践?例如,我的网站 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.
我仍在努力思考前端状态。是否有为资源设置商店的通用最佳实践?例如,我的网站 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.