ReSwift-Thunk icon indicating copy to clipboard operation
ReSwift-Thunk copied to clipboard

add optional label that shows in the object description

Open DivineDominion opened this issue 4 years ago โ€ข 3 comments

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?

DivineDominion avatar Jan 23 '21 11:01 DivineDominion

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?

dani-mp avatar Jan 24 '21 19:01 dani-mp

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 :)

DivineDominion avatar Jan 25 '21 08:01 DivineDominion

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.

dani-mp avatar Jan 25 '21 09:01 dani-mp