Imagine something like Quora.
[
{
type: "question",
answers: [
{
type: "answer",
upvotes: [
{
type: "upvote"
}
/* more upvotes */
],
comments [
{
type: "comment"
}
/* more comments */
]
}
/* more answers */
]
}
/* more questions */
]
I'd surely have something like a QuestionsStore
. But for all child entities I'm unsure what to do with them. Coming from Backbone I'm thinking every answer should have a UpvotesStore
and a CommentsStore
and components would get their data from these Stores and subscribe to updates from them. As far as I understand Flux, "child"/relational stores are somewhat uncommon.
When every component subscribes to updates from QuestionsStore
that leads to something like:
/* in CommentsComponent */
onUpdate: function() {
this.setState({
comments: QuestionsStore.getComments({questionId: 1, answerId: 1});
});
}
or more extreme:
/* in CommentComponent */
onUpdate: function() {
this.setState(QuestionsStore.getComment({questionId: 1, answerId: 1, commentId: 1}));
}
Since the relational data lives in a tree structure, every component needs to know all "parent" id's in order to be able to query their data from QuestionsStore
. I find this somehow weird.
So what is the best Flux pattern to deal with relational (one-to-many) data structure?