I have a web app developed using Facebook's Flux Architecture. The page has two views: one displays a list of TODO items. The second view displays a random set of TODO items.
There are clearly two concerns that need to be managed by stores. The first is the list of available TODO's. The second is the list of randomly selected TODO items.
I thus have a TODOStore
, who's concern is solely of managing the available TODO items. It has actions to loadTODOs
, addTODO
, deleteTODO
, editTODO
. On startup, this store does not load all TODO items. I want it retrieve the list of TODO items from the database only when necessary.
The second store is the RandomTODOListStore
. It's responsibility is to manage the randomly selected TODO items. Seems to me that the RandomTODOListStore
should access the TODO items through the TODOStore
, using TODOStore.getTODOItems()
.
function RandomTODOListStore() {
var $randomTODOs = [];
dispatcher.register(function(payload) {
var action = payload.action;
switch (action.actionType) {
case Constants.LOAD_RANDOM_TODO:
loadRandomTODO();
break;
}
});
function loadRandomTODO() {
$randomTODOs = selectRandom(TODOStore.getTODOList());
emit("change");
}
}
The issue with this is that, as previously stated, the TODOStore
does not load the TODO items on startup.
The question is: "How does the RandomTODOListStore
guarantee that the TODOStore
has already retrieved the TODO items?".