Closed fiskus closed 3 days ago
Attention: Patch coverage is 9.89583%
with 346 lines
in your changes missing coverage. Please review.
Project coverage is 39.21%. Comparing base (
2039532
) to head (279fab0
). Report is 11 commits behind head on master.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
🚨 Try these New Features:
this kind of thing is more commonly done with disjoint unions rather than with plain TS enums, e.g.
interface Loading {
_tag: 'Loading'
}
interface NoAnalytics {
_tag: 'NoAnalytics'
}
interface Data {
_tag: 'Data'
data: ...
}
type State = Loading | NoAnalytics | Data
that way you keep the tag and the data in one place. there are helpers for this in effect:
import { Data } from "effect"
// Define a union type using TaggedEnum
type State = Data.TaggedEnum<{
Loading: {}
NoData: {}
Data: { readonly data: ... }
}>
also, for such a general case, i'd use an abstraction like RemoteData or smth.
oh, and having different states for data / no data seems excessive -- Data: Option<...>
expresses this notion just fine imo.
having different states for data / no data
It's not about if the request has data or not. It's about whether to show data or not. That's type for UI, View-data. That particular component shows "No analytics" when the request is failed. That looks like a mistake. But if this is intentional, we can have comment like "it's legit to have error, that means we don't have analytics" or some named variable.
Was created for demonstration only
So, I didn't like to work with Some/None, and rewrote the code with enum, enumerating states explicitly. It turns out I don't need Effect for this.
Cons:
Pros:
defaultExpanded
is true when there is a dataUsing Typescript tuples makes sure data exists when
State.Data
.Also, if we use an additional component, we can get rid of self-invoking function, but duplicate
<Section />