Skip to content

Commit

Permalink
Fix how cleanup is done in with-copyable
Browse files Browse the repository at this point in the history
  • Loading branch information
wenincode authored and chris-hut committed Oct 16, 2023
1 parent 1a1b951 commit 13e3d1c
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions ui/packages/consul-ui/app/modifiers/with-copyable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}

0 comments on commit 13e3d1c

Please sign in to comment.