diff --git a/packages/@glimmer-workspace/integration-tests/lib/test-helpers/define.ts b/packages/@glimmer-workspace/integration-tests/lib/test-helpers/define.ts index 74e7ac7ee..28633885d 100644 --- a/packages/@glimmer-workspace/integration-tests/lib/test-helpers/define.ts +++ b/packages/@glimmer-workspace/integration-tests/lib/test-helpers/define.ts @@ -82,7 +82,7 @@ class FunctionalModifierManager implements ModifierManager } } - getDebugName(fn: Function) { + getDebugName(fn: SimpleModifierFn) { return fn.name || '(anonymous function)'; } } diff --git a/packages/@glimmer/interfaces/lib/managers/modifier.d.ts b/packages/@glimmer/interfaces/lib/managers/modifier.d.ts index 1c078905d..f6e0ae7c3 100644 --- a/packages/@glimmer/interfaces/lib/managers/modifier.d.ts +++ b/packages/@glimmer/interfaces/lib/managers/modifier.d.ts @@ -19,4 +19,6 @@ export interface ModifierManager { installModifier(instance: ModifierStateBucket, element: Element, args: Arguments): void; updateModifier(instance: ModifierStateBucket, args: Arguments): void; destroyModifier(instance: ModifierStateBucket, args: Arguments): void; + getDebugName?(factory?: unknown): string; + getDebugInstance?(instance: ModifierStateBucket): any; } diff --git a/packages/@glimmer/manager/lib/public/modifier.ts b/packages/@glimmer/manager/lib/public/modifier.ts index ad598d31c..33c35aa3d 100644 --- a/packages/@glimmer/manager/lib/public/modifier.ts +++ b/packages/@glimmer/manager/lib/public/modifier.ts @@ -32,13 +32,12 @@ export function modifierCapabilities { +export interface CustomModifierState { tag: UpdatableTag; element: SimpleElement; - modifier: ModifierInstance; - delegate: ModifierManager; + modifier: ModifierStateBucket; + delegate: ModifierManager; args: Arguments; - debugName?: string; } /** @@ -65,12 +64,12 @@ export interface CustomModifierState { * `updateModifier()` - invoked when the arguments passed to a modifier change * `destroyModifier()` - invoked when the modifier is about to be destroyed */ -export class CustomModifierManager - implements InternalModifierManager> +export class CustomModifierManager + implements InternalModifierManager> { - private componentManagerDelegates = new WeakMap>(); + private componentManagerDelegates = new WeakMap>(); - constructor(private factory: ManagerFactory>) {} + constructor(private factory: ManagerFactory>) {} private getDelegateFor(owner: O) { let { componentManagerDelegates } = this; @@ -99,41 +98,44 @@ export class CustomModifierManager let delegate = this.getDelegateFor(owner); let args = argsProxyFor(capturedArgs, 'modifier'); - let instance: ModifierInstance = delegate.createModifier(definition, args); + let modifier: ModifierStateBucket = delegate.createModifier(definition, args); let tag = createUpdatableTag(); - let state: CustomModifierState; + let state: CustomModifierState; state = { tag, element, delegate, args, - modifier: instance, + modifier, }; - registerDestructor(state, () => delegate.destroyModifier(instance, args)); + registerDestructor(state, () => delegate.destroyModifier(modifier, args)); return state; } getDebugName(definition: object) { - if (typeof definition === 'function') { - return definition.name || definition.toString(); - } else { - return ''; + const delegate = this.factory.prototype; + if (typeof delegate?.getDebugName === 'function') { + return delegate.getDebugName(definition); } + return (definition as any).name || ''; } - getDebugInstance({ modifier }: CustomModifierState) { - return modifier; + getDebugInstance({ delegate, modifier }: CustomModifierState) { + if (typeof delegate?.getDebugInstance === 'function') { + return delegate.getDebugInstance(modifier); + } + return modifier || delegate; } - getTag({ tag }: CustomModifierState) { + getTag({ tag }: CustomModifierState) { return tag; } - install({ element, args, modifier, delegate }: CustomModifierState) { + install({ element, args, modifier, delegate }: CustomModifierState) { let { capabilities } = delegate; if (capabilities.disableAutoTracking === true) { @@ -143,7 +145,7 @@ export class CustomModifierManager } } - update({ args, modifier, delegate }: CustomModifierState) { + update({ args, modifier, delegate }: CustomModifierState) { let { capabilities } = delegate; if (capabilities.disableAutoTracking === true) { @@ -153,7 +155,7 @@ export class CustomModifierManager } } - getDestroyable(state: CustomModifierState) { + getDestroyable(state: CustomModifierState) { return state; } }