javascript - How to handle multiple stores of same type in Flux / ReactJS? -


i'm new flux/react , i'm having hard time understanding of fundamental architecture decisions:

  1. i know stores meant singletons, created @ app start, or can lifetime of store smaller, specific user's actions?
  2. can have multiple instances of same store type, each initialized different context?

unfortunately, examples i've seen seem simplistic answer these questions. let's start facebook's chat app example. there multiple threads each messages. messagestore holds messages entire app , method called getallforthread(id) returns filtered subset of messages. when message comes thread, emits change notification causes messagesection react component re-fetch data (regardless of thread user viewing). doesn't scale. if had 10,000 threads each lots of message activity? here's how decided solve issue:

  1. each messagestore initialized thread id.
  2. create singleton messagestorefactory creates , manages messagestores.
  3. when user clicks on thread, instead of react component subscribing global messagestore, asks messagestorefactory messagestore that specific thread.
  4. if factory has messagestore thread, returns it. otherwise creates one, kicks off async task fetch initial data it, , returns it.
  5. when react component torn down (let's user navigates away it), notifies factory it's done store. using reference counting or other cache logic allow factory prune unused stores.

how far off base approach? there simpler approach still scales?

it seems easier make smarter data fetching according thread user viewing. see facebook's example @ blog-post or presentation?


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -