r-hall
r-hall

Reputation: 11

Flux Utils Stores, and Async Timers

Using the new flux/utils, I have a Store with a timer that needs to be either running or not running depending on the current state of the store. When the timer ends I need to change the state in the store and emit a change.

The problem is that with the new flux utils you can't emit an event outside of the dispatch cycle. How would you handle this?

I don't think doing something like moving the timer into a component is a good idea, similarly having the timer at the api/dispatcher level probably isn't a good idea, since we need to know the state of the store to possibly cancel the timer/etc...

Upvotes: 0

Views: 84

Answers (1)

Cithel
Cithel

Reputation: 696

This is an example of why I find Flux quite difficult to work with sometimes.

A timer is by nature a dynamic element, and in your case it is supposed to change something, that is, trigger an action. This is why I think it would be better in a view.

This way:

  • You can bind your timer state to a state value, so that when the store triggers an emit change, the timer starts or stops automatically.
  • When the timer goes off, your view can trigger an action to change the state in the store and you won't have any issue with the dispatcher.

Hope this will help you

Upvotes: 0

Related Questions