ReSwift-Thunk
ReSwift-Thunk copied to clipboard
add optional label that shows in the object description
Motivation: In my app, I log all actions. This helps with debugging. But sprinkled in now are non-descript log messages like:
๐ 11:47:08: > Thunk<AppState>(body: (Function))
๐ 11:47:09: > Thunk<AppState>(body: (Function))
๐ 11:47:10: > Thunk<AppState>(body: (Function))
With the customizable description, users would be able to see which thunk is being dispatched, e.g.
๐ 11:47:08: > Thunk<AppState>(label: "Requesting users")
๐ 11:47:09: > Thunk<AppState>(label: "Requesting images for user XYZ")
๐ 11:47:09: > Thunk<AppState>(label: "Requesting images for user ABC")
What do y'all think about that?
I wonder if this is something that could be done in a custom middleware?
Another reason for this is that thunks are actually fake ReSwift actions, meaning that they can't affect the state in any way. The real actions that happen inside are the ones that should be logged, IMO.
WDYT?
So you'd say that logging Thunk dispatching doesn't make sense, and instead one should focus on the actual actions? Hm, I can see how adding log(...)
or print statements inside the thunk for debugging purposes to make sense as well. Not sure about the philosophical implications. Logging a useful line instead of "Thunk" would be nice, that's where my argumentation ends :)
Yeah, that's my rationale. A thunk is just something that will eventually create real ReSwift actions.
If instead of dispatching a thunk you would implement the async operation directly in the viewโfor instance, when a user taps a buttonโ, you will expect only the real actions dispatched to be logged.