ctrlplusb / easy-peasy

Vegetarian friendly state for React

Home Page:https://easy-peasy.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there any way to put actions into other actions?

corysimmons opened this issue · comments

I've got a couple super complicated actions. I want to execute one within a conditional in the other one (so actionOn, thunks, effectOn, etc. don't make sense), but everything I've tried has thrown errors.

I've tried passing the action through the initial action's payload.

I've tried importing the store directly into the action and doing stuff like store.dispatch, etc.

I feel like it's not possible, but just asking in case there is a common escape hatch for this.

@corysimmons I'm not sure if this is possible, but just noting that I believe this breaks the basic tenet that actions should be pure and not have side effects. conditionally dispatching an action that updates some state from within another action breaks the purity / predictability of how that action will update state, so I would not be surprised if this is not supported.

is it possible to break the complex action into several smaller, pure actions and encapsulate the conditional logic within a thunk that is responsible for driving the more complex logic and composing the actions?

edit: on second thought, as long as the condition evaluates the same and the result of the action is always the same given the same input then I suppose its still would be considered pure

You're probably right about all that.

It just feels... not-ergonomic... to bust out actions into util helpers then import them everywhere.

Thanks for the sanity check though. I've been mulling it around and came up with all the same stuff.