From 4e1713a87e90c537382b70efd96545ff886ff549 Mon Sep 17 00:00:00 2001 From: Jesse Date: Thu, 23 Jun 2022 17:11:37 -0400 Subject: [PATCH] missing visibility annotations in wilder, see https://github.com/phetsims/chipper/issues/1258 --- js/wilder/WilderScreen.ts | 2 +- js/wilder/model/WilderEnumerationPatterns.ts | 12 ++-- js/wilder/model/WilderModel.ts | 12 ++-- js/wilder/model/WilderOptionsPatterns.ts | 66 ++++++++++---------- js/wilder/view/Mixable.ts | 40 ++++++------ js/wilder/view/WilderNode.ts | 4 +- js/wilder/view/WilderScreenView.ts | 2 +- 7 files changed, 69 insertions(+), 69 deletions(-) diff --git a/js/wilder/WilderScreen.ts b/js/wilder/WilderScreen.ts index b55f0a9..24915c6 100644 --- a/js/wilder/WilderScreen.ts +++ b/js/wilder/WilderScreen.ts @@ -16,7 +16,7 @@ type WilderScreenOptions = { }; class WilderScreen extends Screen { - constructor( providedOptions: WilderScreenOptions ) { + public constructor( providedOptions: WilderScreenOptions ) { const options = { backgroundColorProperty: new Property( 'white' ), diff --git a/js/wilder/model/WilderEnumerationPatterns.ts b/js/wilder/model/WilderEnumerationPatterns.ts index a46adf7..2d8f4a3 100644 --- a/js/wilder/model/WilderEnumerationPatterns.ts +++ b/js/wilder/model/WilderEnumerationPatterns.ts @@ -18,7 +18,7 @@ type WilderEnumerationPatternsOptions = { }; class WilderEnumerationPatterns { - constructor( providedOptions: WilderEnumerationPatternsOptions ) { + public constructor( providedOptions: WilderEnumerationPatternsOptions ) { /************************************************************************ * The primary enumeration pattern. @@ -53,16 +53,16 @@ class WilderEnumerationPatterns { * more values. This should be rarely used. */ class TreeType extends EnumerationValue { - static ASH = new TreeType(); - static BIRCH = new TreeType(); + public static ASH = new TreeType(); + public static BIRCH = new TreeType(); - static enumeration = new Enumeration( TreeType ); + public static enumeration = new Enumeration( TreeType ); } class SpecialTreeType extends TreeType { - static CEDAR = new SpecialTreeType(); + public static CEDAR = new SpecialTreeType(); - static override enumeration = new Enumeration( SpecialTreeType, { + public static override enumeration = new Enumeration( SpecialTreeType, { // Match any static member of SpecialTreeType that is instanceof TreeType, so it will include the existing ASH, BIRCH and also the new value CEDAR instanceType: TreeType diff --git a/js/wilder/model/WilderModel.ts b/js/wilder/model/WilderModel.ts index 0fcd1cc..5fbef38 100644 --- a/js/wilder/model/WilderModel.ts +++ b/js/wilder/model/WilderModel.ts @@ -31,7 +31,7 @@ class WilderModel { private wilderOptionsPatterns: WilderOptionsPatterns; private wilderEnumerationPatterns: WilderEnumerationPatterns; - constructor( providedOptions: WilderModelOptions ) { + public constructor( providedOptions: WilderModelOptions ) { this.wilderOptionsPatterns = new WilderOptionsPatterns(); this.wilderEnumerationPatterns = new WilderEnumerationPatterns( { @@ -192,7 +192,7 @@ class WilderModel { public _mutatorKeys = [ ...Node.prototype._mutatorKeys, 'secret' ]; private _secret: number; - constructor( options?: EmptyObjectType ) { + public constructor( options?: EmptyObjectType ) { // Can't reference `this` before the super() call // Don't pass options here, since want to initialize defaults before passing options to mutate. We still only @@ -205,11 +205,11 @@ class WilderModel { this.mutate( options ); } - set secret( value ) { this._secret = value; } + public set secret( value ) { this._secret = value; } - get secret() { return this._secret; } + public get secret() { return this._secret; } - override dispose(): void { + public override dispose(): void { super.dispose(); this._secret = 0; // Don't tell! } @@ -261,7 +261,7 @@ class WilderModel { /** */ - reset(): void { + public reset(): void { // console.log( 'reset' ); } } diff --git a/js/wilder/model/WilderOptionsPatterns.ts b/js/wilder/model/WilderOptionsPatterns.ts index 7b84a1d..abec367 100644 --- a/js/wilder/model/WilderOptionsPatterns.ts +++ b/js/wilder/model/WilderOptionsPatterns.ts @@ -88,7 +88,7 @@ class Item { private x: number; private y: number; - constructor( providedOptions?: ItemOptions ) { + public constructor( providedOptions?: ItemOptions ) { // In the simplest case, optionize just takes the options that this class defines. const options = optionize()( { @@ -102,7 +102,7 @@ class Item { this.y = options.y; } - getChildren(): Item[] { + public getChildren(): Item[] { return this.children; } } @@ -124,7 +124,7 @@ type MyItemOptions = SelfOptions & ItemOptions; class MyItem extends Item { private mySpecialNumber: number; - constructor( providedOptions?: MyItemOptions ) { + public constructor( providedOptions?: MyItemOptions ) { // Here optionize takes all options that it defines, and also its parent options so that those are allowed to be // passed through the super call. By default, optionize knows what the combined type of "providedOptions" (defaults @@ -158,7 +158,7 @@ type TreeItemOptions = TreeItemSelfOptions & ItemOptions; class TreeItem extends Item { private treeType: TreeItemSelfOptions[ 'treeType' ]; - constructor( providedOptions: TreeItemOptions ) { + public constructor( providedOptions: TreeItemOptions ) { const options = optionize3()( {}, providedOptions ); super( options ); this.treeType = options.treeType; @@ -182,7 +182,7 @@ type ItemContainerOptions = { class ItemContainer { private node: Item; - constructor( providedOptions: ItemContainerOptions ) { + public constructor( providedOptions: ItemContainerOptions ) { const options = optionize()( { nodeOptions: { x: 5, @@ -210,7 +210,7 @@ type ItemContainer2Options = { class ItemContainer2 { private node: Item; - constructor( providedOptions: ItemContainer2Options ) { + public constructor( providedOptions: ItemContainer2Options ) { // TODO: Explicitly omit here until we can work out a way for optionize to detect nested options directly. https://github.com/phetsims/chipper/issues/1128 const options = optionize>()( {}, providedOptions ); @@ -236,7 +236,7 @@ type StationaryItemSelfOptions = EmptyObjectType; type StationaryItemOptions = StationaryItemSelfOptions & StrictOmit; class StationaryItem extends Item { - constructor( providedOptions?: StationaryItemOptions ) { + public constructor( providedOptions?: StationaryItemOptions ) { // Here, since there are no self options, and instead just modified parent options, pass the public options in as the parent options const options = optionize()( {}, providedOptions ); @@ -258,7 +258,7 @@ type ChildrenAdapterItemSelfOptions = EmptyObjectType; type ChildrenAdapterItemOptions = ChildrenAdapterItemSelfOptions & ItemOptions class ChildrenAdapterItem extends Item { - constructor( providedOptions?: ChildrenAdapterItemOptions ) { + public constructor( providedOptions?: ChildrenAdapterItemOptions ) { // Adding the third argument makes sure that children is known to be defined, for usage later in the constructor const options = optionize()( { @@ -289,7 +289,7 @@ type OtherItemSelfOptions = { type OtherItemOptions = OtherItemSelfOptions & ItemOptions; class OtherItem extends Item { - constructor( providedOptions?: OtherItemOptions ) { + public constructor( providedOptions?: OtherItemOptions ) { // NOTE: You must apply a type here in order to get "blarg" to error when uncommented const OTHER_ITEM_DEFAULTS: OptionizeDefaults = { @@ -309,7 +309,7 @@ class OtherItem extends Item { this.test( options.thing ); } - test( x: number ): void { + public test( x: number ): void { console.log( x ); } } @@ -328,7 +328,7 @@ type RequiredThingOptions = { class RequiredThing { - constructor( providedOptions?: RequiredThingOptions ) { + public constructor( providedOptions?: RequiredThingOptions ) { // Here, since there are no self options, and instead just modified parent options, pass the public options in as the parent options const options = optionize()( { @@ -348,9 +348,9 @@ console.log( new RequiredThing() ); // Example Eight: An option is generic class MyGeneric { - optionalThing: G | undefined; + private optionalThing: G | undefined; - constructor( optionalThing?: G ) { + public constructor( optionalThing?: G ) { this.optionalThing = optionalThing; } } @@ -361,9 +361,9 @@ type WrapTypeOptions = { class WrapType { - favoriteGeneric: MyGeneric; + public favoriteGeneric: MyGeneric; - constructor( providedOptions?: WrapTypeOptions ) { + public constructor( providedOptions?: WrapTypeOptions ) { const options = optionize, WrapTypeOptions>()( { favoriteGeneric: new MyGeneric() }, providedOptions ); @@ -371,7 +371,7 @@ class WrapType { this.favoriteGeneric = options.favoriteGeneric; } - getFavoriteItemProperty(): MyGeneric { + public getFavoriteItemProperty(): MyGeneric { return this.favoriteGeneric; } } @@ -393,13 +393,13 @@ type SuperOptions = { } class Super { - howSuper: HowSuper; + private readonly howSuper: HowSuper; - constructor( providedOptions: SuperOptions ) { + public constructor( providedOptions: SuperOptions ) { this.howSuper = providedOptions.howSuper; } - isSuper(): HowSuper { + public isSuper(): HowSuper { return this.howSuper; } } @@ -410,7 +410,7 @@ type KingSelfOptions = { type KingOptions = KingSelfOptions & Partial; class King extends Super { - constructor( providedOptions?: KingOptions ) { + public constructor( providedOptions?: KingOptions ) { // Without the 4th type arg, the super() call doesn't know that howSuper has been provided. This is a workaround // for Limitation (I). Ideally, we wouldn't need the 4th parameter here. @@ -447,7 +447,7 @@ type BlueItemSelfOptions = { type BlutItemOptions = BlueItemSelfOptions & ItemOptions; class BlueItem extends Item { - constructor( providedOptions?: BlutItemOptions ) { + public constructor( providedOptions?: BlutItemOptions ) { // NOTE: isSad can be provided either via the SIM_CONSTANTS objec, or in the object literal, but TypeScript knows // if you leave it out entirely. @@ -463,7 +463,7 @@ class BlueItem extends Item { this.test( options.isSad ); } - test( isSad: string ): void { + public test( isSad: string ): void { console.log( isSad ); } } @@ -481,7 +481,7 @@ type LargeItemSelfOptions = { type LargeItemOptions = LargeItemSelfOptions & ItemOptions; class LargeItem extends Item { - constructor( providedOptions?: LargeItemOptions ) { + public constructor( providedOptions?: LargeItemOptions ) { const options = optionize()( { @@ -511,11 +511,11 @@ type DogOptions = { }; class Dog { - age: number; - name: string; - isGood?: boolean; // Note that since there was no default, Typescript knows it must support undefined + private age: number; + private name: string; + private isGood?: boolean; // Note that since there was no default, Typescript knows it must support undefined - constructor( providedOptions: DogOptions ) { + public constructor( providedOptions: DogOptions ) { const options = optionize()( { age: 0, isGood: true @@ -526,7 +526,7 @@ class Dog { this.isGood = options.isGood; } - printAge(): void { + public printAge(): void { console.log( this.age ); } } @@ -547,9 +547,9 @@ type PersonSelfOptions = { type PersonOptions = PersonSelfOptions; // no parent options class Person { - dog: Dog; + private dog: Dog; - constructor( providedOptions: PersonOptions ) { + public constructor( providedOptions: PersonOptions ) { const options = optionize()( { // (0) (7) New pattern doesn't use `required()` for non-optional options. (like for `name`) @@ -588,7 +588,7 @@ class Employee extends Person { private isRequiredAwesome: boolean; private age: number; - constructor( providedOptions: EmployeeOptions ) { + public constructor( providedOptions: EmployeeOptions ) { // before optionize because it is required console.log( providedOptions.isRequiredAwesome ); @@ -641,7 +641,7 @@ class Employee extends Person { type EmployeeOfTheMonthOptions = StrictOmit class EmployeeOfTheMonth extends Employee { - constructor( providedOptions: EmployeeOfTheMonthOptions ) { // (8), note that if options are optional, then they get a question mark here. + public constructor( providedOptions: EmployeeOfTheMonthOptions ) { // (8), note that if options are optional, then they get a question mark here. const options = optionize()( { // name: 'Bob', // Limitation (I) why doesn't this fail when commented out! It is a required argument to EmployeeOptions but providedOptions is optional? https://github.com/phetsims/chipper/issues/1128 @@ -657,7 +657,7 @@ class WilderOptionsPatterns { private charlie: Employee; private alice: EmployeeOfTheMonth; - constructor() { + public constructor() { this.bob = new Employee( { isRequiredAwesome: true, // (2) diff --git a/js/wilder/view/Mixable.ts b/js/wilder/view/Mixable.ts index fec3bbe..0436398 100644 --- a/js/wilder/view/Mixable.ts +++ b/js/wilder/view/Mixable.ts @@ -34,24 +34,24 @@ function memoize( func: ( k: Key, ...args: any[] ) => Value ) { const GenericMix = memoize( ( type: SuperType ) => { const result = class extends type { - _someField: string; + private _someField: string; - constructor( ...args: any[] ) { + public constructor( ...args: any[] ) { super( ...args ); this._someField = 'Testing'; } - get someField(): string { return this._someField; } + public get someField(): string { return this._someField; } - set someField( value: string ) { this._someField = value; } + public set someField( value: string ) { this._someField = value; } }; return result; } ); class PropertyMixed extends GenericMix( Property ) { - constructor( value: T, options?: PropertyOptions ) { + public constructor( value: T, options?: PropertyOptions ) { super( value, options ); } } @@ -68,10 +68,10 @@ const Mixable = memoize( ( type: SuperType, super assert && assert( _.includes( inheritance( type ), Node ) ); const result = class extends type { - _someField: string; + private _someField: string; // Call args to be (Node, ...args: any[]) - constructor( ...args: any[] ) { + public constructor( ...args: any[] ) { const node = args[ 0 ] as Node; // eslint-disable-next-line no-simple-type-checking-assertions @@ -91,14 +91,14 @@ const Mixable = memoize( ( type: SuperType, super ( this as unknown as Node ).mutate( nodeOptions ); } - get someField(): string { return this._someField; } + public get someField(): string { return this._someField; } - set someField( value: string ) { this._someField = value; } + public set someField( value: string ) { this._someField = value; } /** * @override */ - setVisible( value: boolean ): this { + public setVisible( value: boolean ): this { // console.log( `our bounds: ${( this as unknown as Node ).bounds}` ); // @ts-ignore @@ -115,14 +115,14 @@ const Mixable = memoize( ( type: SuperType, super /// THIS WILL BE IN EACH MIXING TYPE class NodeMixed extends Mixable( Node, 0 ) { - constructor( node: Node, options?: EmptyObjectType ) { + public constructor( node: Node, options?: EmptyObjectType ) { // @ts-ignore super( node, options ); } } class TextMixed extends Mixable( Text, 1 ) { - constructor( node: Node, text: string, options?: EmptyObjectType ) { + public constructor( node: Node, text: string, options?: EmptyObjectType ) { // @ts-ignore super( node, text, options ); } @@ -137,17 +137,17 @@ console.log( `my bar: ${t.someField}` ); ////////////////////////////////////////////////////// const GenericMixin = ( type: SuperType, defaultValue: T ) => { return class extends type { - _someField: T; + public _someField: T; - constructor( ...args: any[] ) { + public constructor( ...args: any[] ) { super( ...args ); this._someField = defaultValue; } - get someField(): T { return this._someField; } + public get someField(): T { return this._someField; } - set someField( value: T ) { this._someField = value; } + public set someField( value: T ) { this._someField = value; } }; }; @@ -320,16 +320,16 @@ const Poolable = ( type: Type, options?: PoolableOptio }; class VectorImpl { - x!: number - y!: number + public x!: number + public y!: number private z!: number; - constructor( x: number, y: number ) { + public constructor( x: number, y: number ) { this.initialize( x, y ); } - initialize( x: number, y: number ): void { + private initialize( x: number, y: number ): void { this.x = x; this.y = y; this.z = 0; diff --git a/js/wilder/view/WilderNode.ts b/js/wilder/view/WilderNode.ts index 0aec54a..dec0cea 100644 --- a/js/wilder/view/WilderNode.ts +++ b/js/wilder/view/WilderNode.ts @@ -13,7 +13,7 @@ import wilder from '../../wilder.js'; import Mixable from './Mixable.js'; class WilderNode extends Node { - constructor( providedOptions?: NodeOptions ) { + public constructor( providedOptions?: NodeOptions ) { const options = optionize()( { children: [ new Text( 'hello wilder' ) ] }, providedOptions ); @@ -25,7 +25,7 @@ class WilderNode extends Node { /** * Rotates the node by PI, demonstrates a class method. */ - flipOver(): void { + public flipOver(): void { this.rotate( Math.PI ); } } diff --git a/js/wilder/view/WilderScreenView.ts b/js/wilder/view/WilderScreenView.ts index ce173d1..4412ed4 100644 --- a/js/wilder/view/WilderScreenView.ts +++ b/js/wilder/view/WilderScreenView.ts @@ -16,7 +16,7 @@ type WilderScreenViewOptions = { }; class WilderScreenView extends ScreenView { - constructor( wilderModel: WilderModel, providedOptions: WilderScreenViewOptions ) { + public constructor( wilderModel: WilderModel, providedOptions: WilderScreenViewOptions ) { super( providedOptions ); const wilderNode = new WilderNode( { x: 100, y: 100 } );