React Flux: Stores

Joe Maddalone
InstructorJoe Maddalone

Share this video with your friends

Send Tweet

Stores are where the real work in our application is done. Dispatchers broadcast Actions to all Stores, and the Stores registered to listen for those Actions will perform any logic needed to update our Views. In this lesson we will establish our first Store and register the Actions we wish to respond to.

Rafael Bitencourt
Rafael Bitencourt
~ 6 years ago

Hello! I'm trying to understand Flux and how everything works and these videos are being super helpful!

Now, on the Store file, it's still a bit strange/confusing to me that we emit change by running AppStore.emitChange() right after our switch statement instead of emitting the change after each function (ie.: after addItem or removeItem) as a callback or something).

Just for testing, I set a timeout on the 'addItem' function to delay its response/logic and the change is emitted 'before' the 'addItem' task has been completed, which breaks the App cause the Cart listens to the 'eventChange' and updates its own state while the latest data isn't there yet.

Should I be concerned about this happening with more complex apps or am I missing something here?

Tks!

Matthew
Matthew
~ 5 years ago

What do you do when you need to use a store in more than one component? Would you require() the store in a parent/controller view then pass it through the props to children?

I've started a Stackoverflow question: http://stackoverflow.com/questions/36380193/how-to-use-store-in-multiple-componenets/36380301#36380301