pauldijou / redux-act

An opinionated lib to create actions and reducers for Redux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom descriptors for batched actions

chacestew opened this issue · comments

commented

Would it be possible to extend the batch method to accept an optional description to use instead of (or appended to) "Batch"? This would improve readability of logs where multiple distinct batch actions are being dispatched.

It's a cool idea, I will try thinking about it since I cannot see an easy solution on how to do that. Maybe you do have one in mind?

commented

I see the complexity: batch is a single action, and all reducers are created with a special handler for its type. We can create batch actions with custom types through e.g. currying, but then reducers will need explicit instructions for these types.

The only solution I have so far is to create a metaReducer for the batch action that sets a custom "description" field on the meta property to use in redux-logger, but this doesn't change other logs or dev tools. Better would be to set a flag "batch" on meta and check for this inside reduce to handle batch actions, in place of the current batch handler, thus allowing any types.

... But this causes the library to start using the meta property, which is probably not acceptable for a small QoL improvement. 😅

So, after thinking more about it, I don't think I will change the lib itself, I would rather try to keep batch as close as possible to a normal standard action without any hack.

That said, you can do something at log time depending on the logger you are using. For example, in the case of redux-logger, the lib is already providing code to improve the logger for batch actions (check README). If you are using another one, try to see if you can do something similar or just name it and I will take a look.