Skip to content

Commit

Permalink
missing visibility annotations in wilder, see phetsims/chipper#1258
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Jun 23, 2022
1 parent a8bf89d commit 4e1713a
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 69 deletions.
2 changes: 1 addition & 1 deletion js/wilder/WilderScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type WilderScreenOptions = {
};

class WilderScreen extends Screen<WilderModel, WilderScreenView> {
constructor( providedOptions: WilderScreenOptions ) {
public constructor( providedOptions: WilderScreenOptions ) {

const options = {
backgroundColorProperty: new Property( 'white' ),
Expand Down
12 changes: 6 additions & 6 deletions js/wilder/model/WilderEnumerationPatterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type WilderEnumerationPatternsOptions = {
};

class WilderEnumerationPatterns {
constructor( providedOptions: WilderEnumerationPatternsOptions ) {
public constructor( providedOptions: WilderEnumerationPatternsOptions ) {

/************************************************************************
* The primary enumeration pattern.
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions js/wilder/model/WilderModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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( {
Expand Down Expand Up @@ -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
Expand All @@ -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!
}
Expand Down Expand Up @@ -261,7 +261,7 @@ class WilderModel {

/**
*/
reset(): void {
public reset(): void {
// console.log( 'reset' );
}
}
Expand Down
66 changes: 33 additions & 33 deletions js/wilder/model/WilderOptionsPatterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemOptions>()( {
Expand All @@ -102,7 +102,7 @@ class Item {
this.y = options.y;
}

getChildren(): Item[] {
public getChildren(): Item[] {
return this.children;
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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<TreeItemOptions, TreeItemSelfOptions, ItemOptions>()( {}, providedOptions );
super( options );
this.treeType = options.treeType;
Expand All @@ -182,7 +182,7 @@ type ItemContainerOptions = {
class ItemContainer {
private node: Item;

constructor( providedOptions: ItemContainerOptions ) {
public constructor( providedOptions: ItemContainerOptions ) {
const options = optionize<ItemContainerOptions>()( {
nodeOptions: {
x: 5,
Expand Down Expand Up @@ -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<ItemContainer2Options, StrictOmit<ItemContainer2Options, 'nodeOptions'>>()( {}, providedOptions );
Expand All @@ -236,7 +236,7 @@ type StationaryItemSelfOptions = EmptyObjectType;
type StationaryItemOptions = StationaryItemSelfOptions & StrictOmit<ItemOptions, 'x' | 'y'>;

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<StationaryItemOptions, StationaryItemSelfOptions, ItemOptions>()( {}, providedOptions );
Expand All @@ -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<ChildrenAdapterItemOptions, ChildrenAdapterItemSelfOptions, ItemOptions>()( {
Expand Down Expand Up @@ -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<OtherItemSelfOptions, ItemOptions, 'x'> = {
Expand All @@ -309,7 +309,7 @@ class OtherItem extends Item {
this.test( options.thing );
}

test( x: number ): void {
public test( x: number ): void {
console.log( x );
}
}
Expand All @@ -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<RequiredThingOptions>()( {
Expand All @@ -348,9 +348,9 @@ console.log( new RequiredThing() );
// Example Eight: An option is generic

class MyGeneric<G> {
optionalThing: G | undefined;
private optionalThing: G | undefined;

constructor( optionalThing?: G ) {
public constructor( optionalThing?: G ) {
this.optionalThing = optionalThing;
}
}
Expand All @@ -361,17 +361,17 @@ type WrapTypeOptions<T> = {


class WrapType<T> {
favoriteGeneric: MyGeneric<T>;
public favoriteGeneric: MyGeneric<T>;

constructor( providedOptions?: WrapTypeOptions<T> ) {
public constructor( providedOptions?: WrapTypeOptions<T> ) {
const options = optionize<WrapTypeOptions<T>, WrapTypeOptions<T>>()( {
favoriteGeneric: new MyGeneric<T>()
}, providedOptions );

this.favoriteGeneric = options.favoriteGeneric;
}

getFavoriteItemProperty(): MyGeneric<T> {
public getFavoriteItemProperty(): MyGeneric<T> {
return this.favoriteGeneric;
}
}
Expand All @@ -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;
}
}
Expand All @@ -410,7 +410,7 @@ type KingSelfOptions = {
type KingOptions = KingSelfOptions & Partial<SuperOptions>;

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.
Expand Down Expand Up @@ -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.
Expand All @@ -463,7 +463,7 @@ class BlueItem extends Item {
this.test( options.isSad );
}

test( isSad: string ): void {
public test( isSad: string ): void {
console.log( isSad );
}
}
Expand All @@ -481,7 +481,7 @@ type LargeItemSelfOptions = {
type LargeItemOptions = LargeItemSelfOptions & ItemOptions;

class LargeItem extends Item {
constructor( providedOptions?: LargeItemOptions ) {
public constructor( providedOptions?: LargeItemOptions ) {

const options = optionize<LargeItemOptions, LargeItemSelfOptions, ItemOptions>()( {

Expand Down Expand Up @@ -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<DogOptions, DogOptions>()( {
age: 0,
isGood: true
Expand All @@ -526,7 +526,7 @@ class Dog {
this.isGood = options.isGood;
}

printAge(): void {
public printAge(): void {
console.log( this.age );
}
}
Expand All @@ -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<PersonOptions, PersonSelfOptions>()( {
// (0) (7) New pattern doesn't use `required()` for non-optional options. (like for `name`)
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -641,7 +641,7 @@ class Employee extends Person {
type EmployeeOfTheMonthOptions = StrictOmit<EmployeeOptions, 'isRequiredAwesome'>

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<EmployeeOfTheMonthOptions, EmptyObjectType, EmployeeOptions>()( {
// 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
Expand All @@ -657,7 +657,7 @@ class WilderOptionsPatterns {
private charlie: Employee;
private alice: EmployeeOfTheMonth;

constructor() {
public constructor() {

this.bob = new Employee( {
isRequiredAwesome: true, // (2)
Expand Down
Loading

0 comments on commit 4e1713a

Please sign in to comment.