Repository navigation
Conversation
…le-with-plane' into noah/plane-compatible-with-plane
There was a problem hiding this comment.
I would argue this is more of a dependency management problem than a typing problem. It's entirely logical and understandable that two versions of a class would be incompatible -- they're supposed to be, since a major purpose of classes is to enable encapsulation.
Because of the shape of Vis as a multi-package library, we do allow devs to install potentially conflicting versions of base packages -- this is helpful because it gives devs the option to select only what they need, but it also allows them to potentially shoot themselves in the foot.
An alternate solution in this case (besides just moving the class into vis-omezarr) would be to make vis-geometry a peer dependency for vis-omezarr, so it would use whichever version the devs have installed, as long as it's within a valid version range.
Using structural typing does indeed have the advantages you're pointing out! But it also has a drawback: our ability to change the implementation of the cartesian plane construct in the future becomes significantly hampered. You just noted that typically they would be implemented differently; if we wanted to make that change later on for any number of reasons, the cost of making the needed changes (not to mention the downstream cost of upgrading) becomes noticeably steeper using structural typing than with nominal typing, since the data implementation is exposed and not encapsulated.
So. All that said: this can become a very, very pedantic discussion! Your implementation works totally fine with Vis as it is, since the majority of the library is already structurally-typed. I just have misgivings from a long-term software health perspective.
lanesawyer
left a comment
There was a problem hiding this comment.
I lean towards preferring the more functional style over class style, so I like what I see here.
But Joel has a good point that we need to manage dependencies better. I think we should move towards peerDependencies in general for the lower-level vis libraries!
What
Why
Because of how classes work in typescript / javascript, different "versions" of the same class may not be assignable to each other. In particular, classes with private data (marked with the
#prefix) are incompatible. This becomes a problem when you look at the cross-dependencies in this codebase. The example of this is a consuming project which imports both vis-geometry and vis-omezarr. Imagine the following: your project imports version 0.1 of vis-geometry, and version 0.1 of vis-omezarr. Now, you need a new feature from vis-geometry: for example 3D rotation math, completely unrelated to ome-zarr rendering in any way - so you update the version of vis-geometry to 0.2, and leave vis-omezarr alone. The result is that you have 2 definitions of the class CartesianPlane, both literally identical. one is transitive via the import of vis-omezarr@0.1 and the other is from vis-geometry@0.2.instances of these classes cannot be assigned to each other! This is a problem because the code your consuming project uses to pass in a plane into the code provided by vis-omezarr can only see one of them - the one from vis-geometry@0.2 - you have no choice but to use the direct dependency version, but code in vis-omezarr@0.1 expects one that matches its transitive dependency. In essence, this is because classes are are nominally typed - despite being identical in source code, their prototype chains do not overlap.
How
the fix is to realize a few things:
Screenshots
This section is optional if there are no visible changes
PR Checklist
main?