Event bus - is it a good idea?

I am building a quiz, the questions are timed. The submit button is 4 levels beneath the timer component.

How should I deal with this scenario, I don’t want to emit the event up the chain. What are my options here? An event bus? Is this good practice? I have kept away from even busses as they feel a little hacky. I could well be wrong.

Any advice or pointers would be appreciated.

You should have a look at VueX. And put your timer in the VueX store. Than in your submit button component you can access this data by getting the data from the store. https://vuex.vuejs.org/

Thanks, that is an option however my timer has event that need to be triggered, stop() start() and reset(). These event are local to the timer component how do I deal with this?

You can stop your timer in the state like so

{
remainingTime: 60,
active: true
}

In your component you can than get values out of state and import start, stop, reset actions with mapActions. In your actions you check if isActive and not 0 if not you can commit start timer mutation and use setInterval to mutate remainingTime every x seconds.

1 Like

nice solution, thanks.