View3d's constructor must currently be supplied with a parent element to which to append the viewer element on creation. This leads to a pattern in website-3d-cell-viewer where the viewer is only created after its containing component has mounted and rendered a container, leading in turn to TypeScript requiring null checks any time view3d is used because it is not definitely assigned in the constructor. Three.js exposes a domElement property on renderers and allows users to add it where they want in the document; if View3d used a similar pattern, it would allow website-3d-cell-viewer to initialize the viewer on component creation and avoid null checks.
Solution
Remove the required parentElement property on View3d's constructor and move it into an optional property on the options object.
When resizing to fit the containing element, get the container by querying canvas3d.containerdiv's parent, rather than storing the provided parent element.
Add method View3d.getDOMElement to get the viewer element.
This is a BREAKING CHANGE to View3d's constructor signature. Some trivial, but ugly, changes could be made to make the constructor backwards-compatible if necessary.
Also, replace a bunch of image null checks with TypeScript's more concise ?. syntax.
Problem
View3d
's constructor must currently be supplied with a parent element to which to append the viewer element on creation. This leads to a pattern in website-3d-cell-viewer where the viewer is only created after its containing component has mounted and rendered a container, leading in turn to TypeScript requiring null checks any timeview3d
is used because it is not definitely assigned in the constructor. Three.js exposes adomElement
property on renderers and allows users to add it where they want in the document; ifView3d
used a similar pattern, it would allow website-3d-cell-viewer to initialize the viewer on component creation and avoid null checks.Solution
parentElement
property onView3d
's constructor and move it into an optional property on the options object.canvas3d.containerdiv
's parent, rather than storing the provided parent element.View3d.getDOMElement
to get the viewer element.This is a BREAKING CHANGE to
View3d
's constructor signature. Some trivial, but ugly, changes could be made to make the constructor backwards-compatible if necessary.Also, replace a bunch of
image
null checks with TypeScript's more concise?.
syntax.