-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix values provided by H5Grove #836
Conversation
packages/app/src/vis-packs/nexus/containers/NxComplexImageContainer.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a complexity layer that is missed by your assertions: the presence of selection
in the params
changes the shape of the array returned from the request. It can even return a scalar value instead of an array.
This means the checks of shapes (such as in h5grove provider and in assertDatasetValue
) must be done according to the asked selection rather than considering the full dataset metadata. Same thing for the flattening.
Right, I need to re-add the Since this edge case isn't something we encounter in the viewer, I don't really see the point of supporting it. At least not in this PR. |
entity: Dataset<ArrayShape>, | ||
selection?: string | ||
) { | ||
assertArray(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will throw if we ask the API to select a scalar, so at least we'll know (in the unlikely event we write code that does this inadvertently).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that given our usecases, we will never get a scalar from an array dataset.
Still it bothers me to prevent it for the following reasons:
- Here and in
assertDatasetValue
usage locations, we have access toselection
. So we could assert according to theselection
. - The type inference in
useDatasetValue
could make use ofdimMapping
to have aValue<D>
corresponding to the gotten slice.
Anyway, this will do for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, it's all doable, but adding this level of type safety to useDatasetValue
means that we then have to assert that the returned value is not scalar inside the relevant containers, which leads to exactly the same result as the assertion that the value returned by the provider is an array regardless of selection
.
If anything, it would make more sense to prevent useDatasetValue
from being called with a dimMapping
that only contains numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way, we still have implicit coupling between useDatasetValue
and the provider APIs' getValue
methods... Perhaps a better solution would be to rethink the signature of getValue
to make this coupling more explicit - e.g. by letting the method accept a dataset rather than an entity, and an optional dimension mapping array with at least one axis in it.
packages/app/src/vis-packs/nexus/containers/NxComplexImageContainer.tsx
Outdated
Show resolved
Hide resolved
entity: Dataset<ArrayShape>, | ||
selection?: string | ||
) { | ||
assertArray(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that given our usecases, we will never get a scalar from an array dataset.
Still it bothers me to prevent it for the following reasons:
- Here and in
assertDatasetValue
usage locations, we have access toselection
. So we could assert according to theselection
. - The type inference in
useDatasetValue
could make use ofdimMapping
to have aValue<D>
corresponding to the gotten slice.
Anyway, this will do for now.
1
.Value<D>
type #824