-
Notifications
You must be signed in to change notification settings - Fork 14
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
Duplicated code between chipper-startup.js and TextBounds.js #775
Comments
After unifying variable names and reordering a method, I'm seeing around 10 lines of code that are duplicated between those files: I'd at least like to understand what possible solutions for factoring these out, to understand their costs. If we just had a preload with initializeTextContainerAttributes(svgTextSizeContainer){
svgTextSizeContainer.setAttribute( 'width', '2' );
svgTextSizeContainer.setAttribute( 'height', '2' );
svgTextSizeContainer.setAttribute( 'style', 'visibility: hidden; pointer-events: none; position: absolute; left: -65535px; right: -65535px;' ); // so we don't flash it in a visible way to the user
}
initializeTextSizeElementAttributes(svgTextSizeElement){
svgTextSizeElement.appendChild( document.createTextNode( '' ) );
svgTextSizeElement.setAttribute( 'dominant-baseline', 'alphabetic' ); // to match Canvas right now
svgTextSizeElement.setAttribute( 'text-rendering', 'geometricPrecision' );
svgTextSizeElement.setAttributeNS( 'http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve' );
} It would guarantee that we are using consistent methods for creating the elements and getting their size. |
It would mean we'd need to modify our build process to include preloads into standalone builds (e.g. Scenery). Additionally, it means we'd need to go through EVERYWHERE that loads Scenery in require.js mode, and add the preload as an additional dependency. This seems like a lot of work for 10 lines (including the maintenance of having a preload just for sharing that much code). Further, it seems like the shared code could get refactored somewhat independently.
It's my fairly strong opinion that it's more trouble. |
At yesterday's dev meeting, we discussed patterns for identifying and referencing code duplicates or code that should be maintained together. @jonathanolson can you please apply that pattern to this work as you see fit? UPDATE: Perhaps unifying the implementation (like matching variable names) would be a good step as part of this. |
From #764
I said
@jonathanolson replied:
The text was updated successfully, but these errors were encountered: