From bc71ebed0343fc958de151c2408c29da0b489313 Mon Sep 17 00:00:00 2001 From: LionelB Date: Tue, 14 Jan 2025 18:58:33 +0100 Subject: [PATCH] refactor(mon-pix): replace will-destroy modifier with willDestroy lifecycle --- .../components/challenge-item/challenge-item-qroc.hbs | 4 ++-- .../app/components/challenge-item/challenge-item-qroc.js | 9 ++++----- mon-pix/app/components/challenge/item.hbs | 1 - mon-pix/app/components/challenge/item.js | 3 ++- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/mon-pix/app/components/challenge-item/challenge-item-qroc.hbs b/mon-pix/app/components/challenge-item/challenge-item-qroc.hbs index 707779ab03b..c2bc1a20086 100644 --- a/mon-pix/app/components/challenge-item/challenge-item-qroc.hbs +++ b/mon-pix/app/components/challenge-item/challenge-item-qroc.hbs @@ -1,4 +1,4 @@ -
+ {{#if this.showProposal}}

{{t "pages.challenge.parts.answer-input"}}

@@ -138,4 +138,4 @@ @isAdjustedCourseForAccessibility={{@assessment.certificationCourse.isAdjustedForAccessibility}} /> {{/if}} - + \ No newline at end of file diff --git a/mon-pix/app/components/challenge-item/challenge-item-qroc.js b/mon-pix/app/components/challenge-item/challenge-item-qroc.js index fc24888973a..899b3fad6c6 100644 --- a/mon-pix/app/components/challenge-item/challenge-item-qroc.js +++ b/mon-pix/app/components/challenge-item/challenge-item-qroc.js @@ -1,3 +1,4 @@ +import { registerDestructor } from '@ember/destroyable'; import { action } from '@ember/object'; import { service } from '@ember/service'; import { tracked } from '@glimmer/tracking'; @@ -52,6 +53,9 @@ export default class ChallengeItemQroc extends ChallengeItemGeneric { _addEventListener() { this.postMessageHandler = this._receiveEmbedMessage.bind(this); window.addEventListener('message', this.postMessageHandler); + registerDestructor(this, () => { + window.removeEventListener('message', this.postMessageHandler); + }); } _receiveEmbedMessage(event) { @@ -107,11 +111,6 @@ export default class ChallengeItemQroc extends ChallengeItemGeneric { this.qrocProposalAnswerValue = value; } - @action - removeEmbedAutoEventListener() { - window.removeEventListener('message', this.postMessageHandler); - } - get _blocks() { return proposalsAsBlocks(this.args.challenge.proposals).map((block) => { block.randomName = generateRandomString(block.input); diff --git a/mon-pix/app/components/challenge/item.hbs b/mon-pix/app/components/challenge/item.hbs index 7dae2ec380f..eed21b98c0a 100644 --- a/mon-pix/app/components/challenge/item.hbs +++ b/mon-pix/app/components/challenge/item.hbs @@ -1,6 +1,5 @@
diff --git a/mon-pix/app/components/challenge/item.js b/mon-pix/app/components/challenge/item.js index e75425f56e2..b4f50954966 100644 --- a/mon-pix/app/components/challenge/item.js +++ b/mon-pix/app/components/challenge/item.js @@ -1,3 +1,4 @@ +import { registerDestructor } from '@ember/destroyable'; import { action } from '@ember/object'; import { service } from '@ember/service'; import { ensureSafeComponent } from '@embroider/util'; @@ -44,7 +45,7 @@ export default class Item extends Component { _setFocusOutEventListener() { document.addEventListener(FOCUSEDOUT_EVENT_NAME, this._focusedoutListener); - + registerDestructor(this, () => this.clearFocusOutEventListener); this._hadFocus = document.hasFocus(); this._pollHasFocusInterval = setInterval(this._pollHasFocus, FOCUSEDOUT_INTERVAL); }