From 13e3d1cdb5793d6d0a92a6abeac6649b8d2c277b Mon Sep 17 00:00:00 2001 From: wenincode Date: Thu, 12 Oct 2023 16:56:05 -0600 Subject: [PATCH] Fix how cleanup is done in with-copyable --- .../consul-ui/app/modifiers/with-copyable.js | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/ui/packages/consul-ui/app/modifiers/with-copyable.js b/ui/packages/consul-ui/app/modifiers/with-copyable.js index 6ffc49187e96..9867607f12e9 100644 --- a/ui/packages/consul-ui/app/modifiers/with-copyable.js +++ b/ui/packages/consul-ui/app/modifiers/with-copyable.js @@ -10,6 +10,16 @@ import { runInDebug } from '@ember/debug'; const typeAssertion = (type, value, withDefault) => { return typeof value === type ? value : withDefault; }; + +function cleanup(instance) { + if (instance?.source && instance?.hash) { + instance.source?.off('success', instance.hash.success)?.off('error', instance.hash.error); + + instance.source?.destroy(); + instance.hash = null; + instance.source = null; + } +} export default class WithCopyableModifier extends Modifier { @service('clipboard/os') clipboard; @@ -39,23 +49,14 @@ export default class WithCopyableModifier extends Modifier { this.hash = hash; } - disconnect() { - if (this.source && this.hash) { - this.source.off('success', this.hash.success).off('error', this.hash.error); - - this.source.destroy(); - this.hash = null; - this.source = null; - } - } - - // lifecycle hooks - didReceiveArguments() { + modify(element, [value], namedArgs) { + this.element = element; this.disconnect(); - this.connect(this.args.positional, this.args.named); + this.connect(value, namedArgs); + registerDestructor(this, cleanup); } - willRemove() { - this.disconnect(); + disconnect() { + cleanup.call(this); } }