From 09de202479f6cdea9d5cbbcd054cd4bea700c950 Mon Sep 17 00:00:00 2001 From: Michael Kauzmann Date: Mon, 29 Apr 2024 16:25:13 -0600 Subject: [PATCH] better pattern for Mixins (RichTextCleanable), https://github.com/phetsims/tasks/issues/1132 Signed-off-by: Michael Kauzmann --- js/util/rich-text/RichTextCleanable.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/js/util/rich-text/RichTextCleanable.ts b/js/util/rich-text/RichTextCleanable.ts index a76aa6270..f3bbe7f6d 100644 --- a/js/util/rich-text/RichTextCleanable.ts +++ b/js/util/rich-text/RichTextCleanable.ts @@ -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( ( type: SuperType ) => { +type TRichTextCleanable = { + readonly isCleanable: boolean; + clean(): void; +}; + +const RichTextCleanable = memoize( ( type: SuperType ): SuperType & Constructor => { 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; } @@ -41,7 +47,7 @@ const RichTextCleanable = memoize( ( type: SuperT } }; } ); -export type RichTextCleanableNode = Node & { clean: () => void; isCleanable: boolean; freeToPool: () => void }; +export type RichTextCleanableNode = Node & TPoolable & TRichTextCleanable; scenery.register( 'RichTextCleanable', RichTextCleanable );