Skip to content

Commit

Permalink
better pattern for Mixins (RichTextCleanable), phetsims/tasks#1132
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Kauzmann <michael.kauzmann@colorado.edu>
  • Loading branch information
zepumph committed Apr 29, 2024
1 parent bb469fe commit 09de202
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions js/util/rich-text/RichTextCleanable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ import inheritance from '../../../../phet-core/js/inheritance.js';
import memoize from '../../../../phet-core/js/memoize.js';
import Constructor from '../../../../phet-core/js/types/Constructor.js';
import { Node, scenery } from '../../imports.js';
import { TPoolable } from '../../../../phet-core/js/Pool.js';

const RichTextCleanable = memoize( <SuperType extends Constructor>( type: SuperType ) => {
type TRichTextCleanable = {
readonly isCleanable: boolean;
clean(): void;
};

const RichTextCleanable = memoize( <SuperType extends Constructor>( type: SuperType ): SuperType & Constructor<TRichTextCleanable> => {
assert && assert( _.includes( inheritance( type ), Node ), 'Only Node subtypes should mix Paintable' );

return class RichTextCleanableMixin extends type {
return class RichTextCleanableMixin extends type implements TRichTextCleanable {
public get isCleanable(): boolean {
return true;
}
Expand All @@ -41,7 +47,7 @@ const RichTextCleanable = memoize( <SuperType extends Constructor>( type: SuperT
}
};
} );
export type RichTextCleanableNode = Node & { clean: () => void; isCleanable: boolean; freeToPool: () => void };
export type RichTextCleanableNode = Node & TPoolable & TRichTextCleanable;

scenery.register( 'RichTextCleanable', RichTextCleanable );

Expand Down

0 comments on commit 09de202

Please sign in to comment.