Search code examples
javascriptfluxreduxperiodicity

Redux and periodic actions


To illustrate the use-case, I have a </video> tag that dispatches an action every time (~250ms) the playhead moves. I'm not a Flux/Redux's guru and I'm facing some issues:

  • Is it a valid approach ?
  • With a weighty state, may it cause performance issues ?
  • Do you have any optimisation proposals about subscribing to a part of the state changes ?

Many many thanks for you help !


Solution

  • I think the approach is reasonable (especially if you are wanting to use information from that video element across the application), and depending on the app/actions, there may be consequences.

    If you are using React with Redux, the connect higher-order component can take a pure: true option to do a shallow compare of props in the shouldComponentUpdate callback that might help prevent too many re-renders.

    Otherwise you could use a store enhancer or higher-order reducer to specially handle the actions fired by the video element. The redux-ignore middleware may help with that or provide a pattern for doing so.