-
Notifications
You must be signed in to change notification settings - Fork 0
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
Code Review: Kitten and Location Representations #32
Comments
I'm unlikely to get through all of this in one sitting, so here's feedback on what I've reviewed so far. KittenNode
newKittenFocusedEmitter.emit();
model.focusedProperty.value = true; ... and then you could do something like:
model.attributePositionProperty.value = options.initialPosition; KittenLayerNodeSee above for KittenNode above renaming See above for KittenNode about initializing |
CommutativeButton
![]() TenFrameButton
createTenFrameIcon private static createTenFrameIcon(): Node {
const tenFrameWidth = 48;
const tenFrameHeight = 22;
const tenFrameLineWidth = 2;
// outer frame
const shape = new Shape().rect( 0, 0, tenFrameWidth, tenFrameHeight );
shape.moveTo( 0, tenFrameHeight / 2 );
// horizontal line
shape.lineTo( tenFrameWidth, tenFrameHeight / 2 );
// vertical lines
const verticalLineSpacing = tenFrameWidth / 5;
_.times( 4, i => {
shape.moveTo( verticalLineSpacing + i * verticalLineSpacing, 0 );
shape.lineTo( verticalLineSpacing + i * verticalLineSpacing, tenFrameHeight );
} );
return new Path( shape, {
stroke: 'black',
lineWidth: tenFrameLineWidth
} );
}
patchSubject: [PATCH] fix hBox layout at bottom of SnapshotsAccordionBox, https://github.com/phetsims/equality-explorer/issues/224
---
Index: js/common/view/NumberPairsScreenView.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/common/view/NumberPairsScreenView.ts b/js/common/view/NumberPairsScreenView.ts
--- a/js/common/view/NumberPairsScreenView.ts (revision ce5dd523244167a04d0eac8e3f903543f4780a08)
+++ b/js/common/view/NumberPairsScreenView.ts (date 1732311692146)
@@ -140,7 +140,7 @@
// we have access to the countingAreaBounds which are defined during construction.
const sumTenFrameBounds = this.countingAreaBounds.erodedX( this.countingAreaBounds.width / 3.5 );
const tenFrameBounds = options.sumScreen ? [ sumTenFrameBounds ] : NumberPairsScreenView.splitBoundsInHalf( this.countingAreaBounds );
- const tenFrameButton = new TenFrameButton( tenFrameBounds, model.organizeIntoTenFrame.bind( model ), {
+ const tenFrameButton = new TenFrameButton( () => model.organizeIntoTenFrame( tenFrameBounds ), {
tandem: options.tandem.createTandem( 'tenFrameButton' ),
visibleProperty: tenFrameButtonVisibleProperty
} );
Index: js/common/view/TenFrameButton.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/common/view/TenFrameButton.ts b/js/common/view/TenFrameButton.ts
--- a/js/common/view/TenFrameButton.ts (revision ce5dd523244167a04d0eac8e3f903543f4780a08)
+++ b/js/common/view/TenFrameButton.ts (date 1732311692170)
@@ -22,17 +22,14 @@
export default class TenFrameButton extends RectangularPushButton {
public constructor(
- tenFrameBounds: Bounds2[],
- organizeIntoTenFrame: ( bounds: Bounds2[] ) => void,
+ organizeIntoTenFrame: () => void,
providedOptions: TenFrameButtonOptions
) {
const tenFrameIcon = TenFrameButton.createTenFrameIcon();
const options = optionize4<TenFrameButtonOptions, SelfOptions, RectangularPushButtonOptions>()( {},
{
content: tenFrameIcon,
- listener: () => {
- organizeIntoTenFrame( tenFrameBounds );
- }
+ listener: organizeIntoTenFrame
}, NumberPairsConstants.RECTANGULAR_PUSH_BUTTON_OPTIONS, providedOptions );
super( options );
} Here's another pattern you might consider for both CommutativeButton and TenFrameButton. Rather than adding construtor parameters, it simply makes patchSubject: [PATCH] fix hBox layout at bottom of SnapshotsAccordionBox, https://github.com/phetsims/equality-explorer/issues/224
---
Index: js/common/view/NumberPairsScreenView.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/common/view/NumberPairsScreenView.ts b/js/common/view/NumberPairsScreenView.ts
--- a/js/common/view/NumberPairsScreenView.ts (revision ce5dd523244167a04d0eac8e3f903543f4780a08)
+++ b/js/common/view/NumberPairsScreenView.ts (date 1732312565858)
@@ -140,7 +140,8 @@
// we have access to the countingAreaBounds which are defined during construction.
const sumTenFrameBounds = this.countingAreaBounds.erodedX( this.countingAreaBounds.width / 3.5 );
const tenFrameBounds = options.sumScreen ? [ sumTenFrameBounds ] : NumberPairsScreenView.splitBoundsInHalf( this.countingAreaBounds );
- const tenFrameButton = new TenFrameButton( tenFrameBounds, model.organizeIntoTenFrame.bind( model ), {
+ const tenFrameButton = new TenFrameButton( {
+ listener: () => model.organizeIntoTenFrame( tenFrameBounds ),
tandem: options.tandem.createTandem( 'tenFrameButton' ),
visibleProperty: tenFrameButtonVisibleProperty
} );
@@ -150,7 +151,8 @@
tandem: options.tandem.createTandem( 'organizeBeadsButton' ),
visibleProperty: organizeButtonVisibleProperty
} );
- const commutativeButton = new CommutativeButton( model.swapAddends.bind( model ), {
+ const commutativeButton = new CommutativeButton( {
+ listener: () => model.swapAddends(),
tandem: options.tandem.createTandem( 'commutativeButton' )
} );
const countingAreaButtonsVBox = new VBox( {
Index: js/common/view/CommutativeButton.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/common/view/CommutativeButton.ts b/js/common/view/CommutativeButton.ts
--- a/js/common/view/CommutativeButton.ts (revision ce5dd523244167a04d0eac8e3f903543f4780a08)
+++ b/js/common/view/CommutativeButton.ts (date 1732312565847)
@@ -20,17 +20,16 @@
type SelfOptions = EmptySelfOptions;
type CommutativeButtonOptions =
SelfOptions
- & PickRequired<RectangularPushButtonOptions, 'tandem'>
- & StrictOmit<RectangularPushButtonOptions, 'content' | 'listener'>;
+ & PickRequired<RectangularPushButtonOptions, 'tandem' | 'listener'>
+ & StrictOmit<RectangularPushButtonOptions, 'content'>;
export default class CommutativeButton extends RectangularPushButton {
- public constructor( swapAddends: () => void, providedOptions: CommutativeButtonOptions ) {
+ public constructor( providedOptions: CommutativeButtonOptions ) {
const commutativeArrowsIcon = CommutativeButton.createCommutativeArrowsIcon();
const options = optionize4<CommutativeButtonOptions, SelfOptions, RectangularPushButtonOptions>()( {},
{
content: commutativeArrowsIcon,
- listener: swapAddends
}, NumberPairsConstants.RECTANGULAR_PUSH_BUTTON_OPTIONS, providedOptions );
super( options );
}
Index: js/common/view/TenFrameButton.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/common/view/TenFrameButton.ts b/js/common/view/TenFrameButton.ts
--- a/js/common/view/TenFrameButton.ts (revision ce5dd523244167a04d0eac8e3f903543f4780a08)
+++ b/js/common/view/TenFrameButton.ts (date 1732312565865)
@@ -16,23 +16,16 @@
import Bounds2 from '../../../../dot/js/Bounds2.js';
type SelfOptions = EmptySelfOptions;
-type TenFrameButtonOptions = SelfOptions & PickRequired<RectangularPushButtonOptions, 'tandem'>
- & StrictOmit<RectangularPushButtonOptions, 'content' | 'listener'>;
+type TenFrameButtonOptions = SelfOptions & PickRequired<RectangularPushButtonOptions, 'tandem' | 'listener'>
+ & StrictOmit<RectangularPushButtonOptions, 'content'>;
export default class TenFrameButton extends RectangularPushButton {
- public constructor(
- tenFrameBounds: Bounds2[],
- organizeIntoTenFrame: ( bounds: Bounds2[] ) => void,
- providedOptions: TenFrameButtonOptions
- ) {
+ public constructor( providedOptions: TenFrameButtonOptions ) {
const tenFrameIcon = TenFrameButton.createTenFrameIcon();
const options = optionize4<TenFrameButtonOptions, SelfOptions, RectangularPushButtonOptions>()( {},
{
content: tenFrameIcon,
- listener: () => {
- organizeIntoTenFrame( tenFrameBounds );
- }
}, NumberPairsConstants.RECTANGULAR_PUSH_BUTTON_OPTIONS, providedOptions );
super( options );
} |
// LocationCountingObjectNode.ts
// Create the one card.
const oneCard = new Rectangle( 0, 0, IMAGE_WIDTH, ONE_CARD_HEIGHT, {
fill: 'white',
stroke: 'black',
cornerRadius: 5,
visibleProperty: DerivedProperty.valueEqualsConstant( countingRepresentationTypeProperty, RepresentationType.ONE_CARDS )
} );
const numberOne = new Text( '1', {
font: new PhetFont( 40 ),
center: oneCard.center,
visibleProperty: DerivedProperty.valueEqualsConstant( countingRepresentationTypeProperty, RepresentationType.ONE_CARDS )
} );
oneCard.addChild( numberOne );
// CountingObjectControl.ts
const createNumberLineIcon = ( fill: TColor ) => {
const icon = new Rectangle( 0, 0, MAX_ICON_WIDTH, MAX_ICON_HEIGHT, {
fill: fill,
cornerRadius: 5
} );
const numberOne = new Text( '1', {
font: new PhetFont( 24 ),
center: icon.center
} );
icon.addChild( numberOne );
return icon;
};
// RepresentationType.ts
new Rectangle( 0, 0, ICON_MAX_WIDTH, ICON_MAX_HEIGHT, {
cornerRadius: 5,
fill: Color.WHITE,
stroke: 'black',
children: [ new Text( '1', { font: new PhetFont( 18 ), center: new Vector2( ICON_MAX_WIDTH / 2, ICON_MAX_HEIGHT / 2 ) } ) ]
} ) |
LocationCountingObjectsLayerNode
accessibleName: 'Location Counting Objects' |
CountingObject
export const KITTEN_PANEL_WIDTH = 56;
export const KITTEN_PANEL_HEIGHT = 82;
export const KITTEN_PANEL_MARGIN = 3;
|
There are currently 12 occurrences of For example, in NumberCircle: Subject: [PATCH] fix hBox layout at bottom of SnapshotsAccordionBox, https://github.com/phetsims/equality-explorer/issues/224
---
Index: js/common/view/NumberCircle.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/common/view/NumberCircle.ts b/js/common/view/NumberCircle.ts
--- a/js/common/view/NumberCircle.ts (revision eb6dd1a63cd7ff5aaca058d71cab655fac1c2e9e)
+++ b/js/common/view/NumberCircle.ts (date 1732316585885)
@@ -17,8 +17,10 @@
type NumberCircleOptions = StrictOmit<CircleOptions, 'children' | 'radius'>;
-export const CIRCLE_RADIUS = 30;
export default class NumberCircle extends Circle {
+
+ public static readonly RADIUS = 30;
+
public constructor(
numberProperty: TReadOnlyProperty<number>,
numberVisibleProperty: TReadOnlyProperty<boolean>,
@@ -28,7 +30,7 @@
stroke: 'black',
excludeInvisibleChildrenFromBounds: true
}, providedOptions );
- super( CIRCLE_RADIUS, options );
+ super( NumberCircle.RADIUS, options );
const numberStringProperty = new DerivedProperty( [ numberProperty ], ( number: number ) => number.toString() );
const numberText = new Text( numberStringProperty, { |
NumberPairsModel
NumberPairsScreenView
|
I’ve been ignoring this for awhile, but have changed my mind and decided to bring it up. There are many places with field or parameter |
LocationCountingObjectNode
|
Review is done. Back to you @marlitas. Let me know if you have any questions. |
I looked into this. In previous sims all of my animations have been in the model so this was a bit surprising to hear ( However, I am having to rethink some things for #23. The code is currently making some assumptions that is blocking some animation requests therefore it might coincide to hit this with that work as well. |
…rties for proper reset behavior, see: #32
Addressing this point led me to a large refactor that I hope makes reset and construction more straightforward. The benefit is that reset also behaves more closely to phet-io state setting which seems easier to digest and navigate. I'm going to keep an eye on CT for any issues this may have brought up, but I tried to test various scenarios throughout the sim as well. |
I don't believe so because it is mostly needed for user interaction purposes which is not an issue in state setting. I added more documentation to the |
The animation is so closely tied to position Properties in the model that I don't think it's worth trying to move to the view. If we did we would also have to move the swap addends logic as well as the ten frame logic to the view which feels much more at home in the model. I think it's best to leave the animation as is. |
Re #32 (comment) ...
Yes, nice documentation, very helpful. |
937c31d is a large commit. I spent ~10 minutes skimming it. While I may have missed some subtlety, I don't see any obvious problems, and it addresses my review comment about initializing and resetting Very minor feedback... In DecompositionModel.ts this const could benefit from documentation: const INITIAL_VALUES_DIFFERENCE = 1; Back to @marlitas for next steps. |
I don't remember what state it was in during this review, but I added a bit of documentation and there is refinement work that will need to be done. I created a new issue for that: #77 |
I need to do accessible name work in general. Issue for that: #78 |
@pixelzoom Why is this the convention? With export const I don't have to remember what class the const is connected to and I can get an auto complete. With class constants I generally have to search to find the class first and then can access the const. It's kind of annoying in terms of efficiency. |
…erPairsUtils for bounds splitting and improve code organization, see: #32
It's pretty typical of all OO programming languages, and it clearly associates a constant with what it pertains to. If you want to do something else, go for it. Just be aware that you're doing something that you're unlikely to see in other OO languages. |
Btw... The same goes for static methods. There's no reason you couldn't define them as plain old functions outside of the class definition and export them separately. But that's not "the OO way". |
Here's another example of why static constants are preferrable. class Proton {
public static readonly RADIUS = 6;
...
}
class Electron {
public static readonly RADIUS = 5;
...
} So when you see |
Thanks for the reply @pixelzoom I will move many to be static constants then. How do you feel about static constants vs. constants that live in |
That's a good question. I tend to put things in |
I refactored how constants are organized. most |
A review for both the model and view classes that create the Kitten and Location-based representations would be helpful, and I believe was not part of the review in #20
Please feel free to close this issue if that is incorrect.
Classes that should be a part of this review:
Additionally, logic was added to the following files due to the implementation of the above:
The text was updated successfully, but these errors were encountered: