trovit / reffects

Reffects is a Javascript framework for developing SPAs using an event-driven unidirectional flow architecture with a synchronous event bus with effects and coeffects.
MIT License
30 stars 15 forks source link

Effects list as an Array #58

Open mariosanchez opened 3 years ago

mariosanchez commented 3 years ago

Feature request

Is your feature request related to a problem? Please describe. Nowadays when we want to ensure the order of execution of certain effects we can't do it unless we use auxiliary event handlers to encapsulate them and then use {{dispatchMany}} (which ensure us the order of dispatch).

For example, maybe I want to mutate state, but at the same time do a side effect (dispatching another event) which relies that this state mutation happened before of this effect handler execution.

Describe the solution you'd like I propose to have a reverse compatible implementation which supports returning an array in an event handler being possible to do:

return [
    state.set ({all: newTodos}),
    effects.dispatch ("anEvent"),
]

Instead of:

return {
    ... state.set ({all: newAll}),
    ... effects.dispatch ("anEvent"),
}

The first one will ensure you the effect handler execution order in the sequence you declare the effects.

Also, you avoid using spread operator.

Describe alternatives you've considered You also can pass to the state effect and the dispatched event in the payload the same value and ignore the execution order in some scenarios (is the solution I've use).

trikitrok commented 3 years ago

I think, the alternative you described "passing to the state effect and the dispatched event in the payload the same value" should be preferred, because it avoids the temporal coupling altogether.