-
Notifications
You must be signed in to change notification settings - Fork 8
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
create additional type-specific Property subclasses? #221
Comments
@zepumph was investigating an approach that would eliminate one of On the other hand, I'm not opposed to creating this.locationProperty = new TypedProperty( options.initialLocation, Vector2, {
tandem: options.tandem.createTandem( 'locationProperty' )
}); or this.locationProperty = new TypedProperty( options.initialLocation, {
phetioType: PropertyIO(Vector2IO), // valueType is inferred from this
tandem: options.tandem.createTandem( 'locationProperty' )
}); etc. |
I think I would prefer just adding more type-specific Property subclasses instead of something general, unless we switched to using only using the general type. It might be weird to be able to do the same thing three different ways: this.activeProperty = new Property( false, {
phetioType: PropertyIO( BooleanIO ),
tandem: options.tandem.createTandem( 'activeProperty' )
} ); and this.activeProperty = new BooleanProperty( false, {
tandem: options.tandem.createTandem( 'activeProperty' )
} ); and this.activeProperty = new Property( false, Boolean, {
tandem: options.tandem.createTandem( 'activeProperty' )
} ); |
We should also create |
Should we go the extra mile and prevent types like |
Could that be done with a lint rule? |
JS is not a statically typed language and hence we cannot determine the type of a value passed into Property until runtime. So this cannot be done with a lint rule. |
Thanks, that makes sense. I was hoping we could search for |
Does this still need to be labeled for developer meeting? |
I would defer to @pixelzoom's judgement on that. From #221 (comment):
Yes indeed, see #204 When that is added, likely we are talking about one line of code difference. I agree that it is very nice to not have to repeat the type creation everywhere you need to create an instance. I would think that only a few other specific Property subtypes would be warranted though. |
Did we come to a consensus at last week's dev meeting? I don't see any comment with dev meeting notes. |
I think we decided that we'd go ahead and add a few other type-specific Property subclasses, but I don't remember finalizing which ones. |
I added this code to the Property constructor: window.top.propertyMap = window.top.propertyMap || {};
if ( value && value.constructor && value.constructor.name ) {
window.top.propertyMap[ value.constructor.name ] = window.top.propertyMap[ value.constructor.name ] || 0;
window.top.propertyMap[ value.constructor.name ]++;
} and ran local aqua. This reports the number of instances of Property with constructor names on instantiation. Here is the result, and a script that sorts: /* eslint-disable */
var x = {
"String": 10215,
"Boolean": 480006,
"Number": 40877,
"Bounds2": 862,
"Vector2": 37912,
"Color": 82536,
"RangeWithValue": 121,
"Object": 305,
"PerimeterShape": 8,
"ImmutableVector2": 21153,
"Orientation": 65,
"Array": 449,
"ProportionalArea": 5,
"Polynomial": 307,
"TermList": 10,
"Partition": 40,
"NumberProperty": 43,
"Range": 1387,
"ModelViewTransform2": 24,
"PartitionedArea": 44,
"Term": 1707,
"DynamicProperty": 5,
"GenericLayout": 8,
"GenericArea": 5,
"DerivedProperty": 6,
"GenericPartition": 12,
"AreaChallenge": 14,
"Entry": 38,
"HTMLImageElement": 89,
"SynthesisEquation": 2,
"DecompositionEquation": 1,
"Solute": 7,
"BeersLawSolution": 1,
"LaserColor": 3,
"Medium": 6,
"Substance": 6,
"Polygon": 70,
"Circle": 15,
"SemiCircle": 7,
"Fraction": 388,
"FractionChallenge": 80,
"KitCollection": 5,
"Rectangle": 4,
"BAAGameState": 1,
"Bounds3": 2,
"Vector3": 481,
"Shape": 226,
"Property": 13,
"Vertex": 746,
"ShapesScene": 2,
"NumbersScene": 2,
"VariablesScene": 1,
"ConstantTerm": 5,
"OperationsScene": 1,
"LabScene": 1,
"TwoVariablesScene": 1,
"Dimension2": 310,
"Dimension3": 203,
"SquarePoolModel": 2,
"MatchSpot": 31,
"MatchingChallenge": 24,
"PatternsScene": 2,
"EquationsScene": 1,
"MysteryScene": 1,
"FBBMysteryScene": 1,
"MotionBounds": 108,
"GeneA": 1,
"Line": 170,
"GraphTheLine": 2,
"Quadratic": 12,
"GravityAndOrbitsMode": 2,
"Residual": 85,
"Level": 1,
"Body": 10,
"RealMolecule": 3,
"VSEPRMolecule": 2,
"RealMoleculeShape": 2,
"Pendulum": 3,
"ProjectileObjectType": 4,
"DataPoint": 14,
"RadialGradient": 1,
"NecklaceLayout": 20,
"PaintChoice": 3,
"NecklaceScene": 2,
"Image": 17,
"SandwichNode": 2,
"SandwichRecipe": 1,
"H2Node": 58,
"O2Node": 98,
"H2ONode": 58,
"N2Node": 26,
"NH3Node": 23,
"CH4Node": 24,
"CO2Node": 21,
"Reaction": 1,
"PCl3Node": 8,
"Cl2Node": 16,
"PCl5Node": 4,
"NONode": 22,
"CONode": 12,
"F2Node": 14,
"OF2Node": 6,
"HFNode": 5,
"CNode": 12,
"C2H5OHNode": 4,
"SNode": 10,
"CS2Node": 4,
"H2SNode": 6,
"C2H2Node": 16,
"SO2Node": 8,
"C2H4Node": 4,
"C2H6Node": 16,
"CH2ONode": 4,
"CH3OHNode": 2,
"NO2Node": 8,
"N2ONode": 4,
"P4Node": 12,
"PF3Node": 4,
"PH3Node": 2,
"HClNode": 4,
"Easing": 2,
"FruitScene": 2,
"VegetableScene": 2,
"CandyScene": 2,
"ShoppingCategory": 2,
"WaterScene": 3
};
var array = Object.keys( x ).map( k => {return { key: k, value: x[ k ] }} );
console.log( array );
array.sort( ( a, b ) => b.value - a.value );
const result = array.map( a => a.key + ': ' + a.value ).join( '\n' );
console.log( result );
|
Taking a closer look with everything 1000 or over:
We already have BooleanProperty and NumberProperty and StringProperty. That leaves ColorProperty and Vector2Property. RangeProperty seems on the lower side, but we could add it too if desired. Term seems simulation specific, so would not be implemented in axon, if at all. Therefore, I propose the following next steps:
@pixelzoom does this sound like a good plan to you? If so, we can open new issues for 1-3 and close this one. |
ColorProperty and Vector2Property sound good. They are the 2 that I had zeroed in on in #221 (comment). Unless there's a straightforward implementation of (3), I would be inclined to skip it and address during code review and PhET-iO instrumentation. That seems to be working for the current Properties subclasses. |
Some more questions before this can be split out into issues. Should ColorProperty be declared in scenery or axon? Should Vector2Property be declared in dot or axon? |
That's probably depends on what dependencies are desired (or possible), and might be a better question for @jonathanolson. |
For scalability and to avoid odd repo-repo dependencies, it seems appropriate for the |
We agreed we will put the *Property next to the * types. |
It shouldn't, they seem to serve different purposes. |
Please elaborate. And please provide input on how ColorProperty should work. |
PaintColorProperty effectively takes a ColorProperty would presumably be like a normal |
The open issue is whether this "color Property" should take a value of type |
In #274 we discussed adding RangeProperty. |
I'm only seeing 3 occurrences of
PhET-iO support may be more straightforward if it just uses |
Today during dev meeting we decided that it was easy and forward thinking to create the following Properties:
For PhET-iO instrumentation, we decided not to eagerly instrument some of these with no instrumented usages. We should instrument
|
PaintColorProperty was added in phetsims/scenery@04abdf6, which takes PaintDef values. |
I added ColorProperty. PaintColorProperty already supports PaintDef values. @jonathanolson can you comment whether ColorDefProperty should look more like ColorProperty implementation or PaintColorProperty implementation? |
PaintColorProperty converts |
We may want to defer this until we discuss phetsims/scenery#1135 (revisit "color" and "paint"). |
Somewhat related to #196...
Should we create any additional type-specific Property subclasses, for types that occur frequently? The primary reason I'm asking is because of the boilerplate PhET-iO instrumentation that is involved, especially for type description/validation.
Looking through the sims that I'm responsible for, I see frequent occurrences of
Property.<Vector2>}
and{Property.<Color>}
. Every ScreenView has an instance of the latter, and they also appear inColorProfile
.So for example this boilerplate:
... could be replaced with:
The text was updated successfully, but these errors were encountered: