Skip to content

Commit

Permalink
Move destroy handler registration 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 0fd98e7 commit 0519b9b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ui/packages/consul-ui/app/modifiers/with-copyable.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const typeAssertion = (type, value, withDefault) => {
};

function cleanup(instance) {
if (instance?.source && instance?.hash) {
if (instance && instance?.source && instance?.hash) {
instance.source?.off('success', instance.hash.success)?.off('error', instance.hash.error);

instance.source?.destroy();
Expand Down Expand Up @@ -49,11 +49,15 @@ export default class WithCopyableModifier extends Modifier {
this.hash = hash;
}

constructor() {
super(...arguments);
registerDestructor(this, cleanup);
}

modify(element, [value], namedArgs) {
this.element = element;
this.disconnect();
this.connect(value, namedArgs);
registerDestructor(this, cleanup);
}

disconnect() {
Expand Down

0 comments on commit 0519b9b

Please sign in to comment.