You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This has now been requested multiple times so I want to make it happen.
It is useful for consumers of Circuit and similar architectures, where the view model is a data class with a view event callback, e.g.:
data classCounterState(
valcount:Int,
valeventSink: (CounterEvent) ->Unit,
) : CircuitUiState
A drawback of this is that as a lambda type, eventSink does not implement equals, and thus two instances of CounterState will never be equals. This can't be fixed with data classes, but it is possible to work around this in Poko by moving the property declaration of eventSink out of the constructor:
But this is annoying to write, and it's not clear why the code is written this way to someone who doesn't already know.
In #182, @ZacSweers proposes a flag in the @Poko annotation to exclude lambda types from Poko's function generation. I think this would be too inflexible, and it would require Poko to maintain a list of types that this flag should apply to.
In the same PR, @JakeWharton proposes a new annotation applied to properties that Poko should skip. This is more verbose, but is more flexible and more explicit. The example above is simplified to this:
Do prospective consumers of this API need support for a custom annotation class, similar to that for @Poko?
The skipped property will be omitted from equals and hashCode completely. How should toString behave? My inclination was to omit it, but open to changing that.
The text was updated successfully, but these errors were encountered:
This has now been requested multiple times so I want to make it happen.
It is useful for consumers of Circuit and similar architectures, where the view model is a data class with a view event callback, e.g.:
A drawback of this is that as a lambda type,
eventSink
does not implementequals
, and thus two instances ofCounterState
will never be equals. This can't be fixed with data classes, but it is possible to work around this in Poko by moving the property declaration ofeventSink
out of the constructor:But this is annoying to write, and it's not clear why the code is written this way to someone who doesn't already know.
In #182, @ZacSweers proposes a flag in the
@Poko
annotation to exclude lambda types from Poko's function generation. I think this would be too inflexible, and it would require Poko to maintain a list of types that this flag should apply to.In the same PR, @JakeWharton proposes a new annotation applied to properties that Poko should skip. This is more verbose, but is more flexible and more explicit. The example above is simplified to this:
I'm in favor of this approach. It's pretty trivial to implement, but a few details need to be decided:
@PokoSkip
,@PokoIgnore
,@Skip
,@Ignore
, ...?@Poko
?equals
andhashCode
completely. How shouldtoString
behave? My inclination was to omit it, but open to changing that.The text was updated successfully, but these errors were encountered: