Skip to content

Commit

Permalink
refactor(mon-pix): replace will-destroy modifier with willDestroy lif…
Browse files Browse the repository at this point in the history
…ecycle
  • Loading branch information
lionelB committed Jan 15, 2025
1 parent 98bf4d4 commit bc71ebe
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions mon-pix/app/components/challenge-item/challenge-item-qroc.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form {{will-destroy this.removeEmbedAutoEventListener}} {{on "submit" this.validateAnswer}}>
<form {{on "submit" this.validateAnswer}}>
{{#if this.showProposal}}
<div class="rounded-panel__row challenge-response {{if @answer 'challenge-response--locked'}}">
<h2 class="sr-only">{{t "pages.challenge.parts.answer-input"}}</h2>
Expand Down Expand Up @@ -138,4 +138,4 @@
@isAdjustedCourseForAccessibility={{@assessment.certificationCourse.isAdjustedForAccessibility}}
/>
{{/if}}
</form>
</form>
9 changes: 4 additions & 5 deletions mon-pix/app/components/challenge-item/challenge-item-qroc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { registerDestructor } from '@ember/destroyable';
import { action } from '@ember/object';
import { service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion mon-pix/app/components/challenge/item.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<article
class="rounded-panel rounded-panel--no-margin-bottom challenge-item"
{{will-destroy this.clearFocusOutEventListener}}
data-challenge-id="{{@challenge.id}}"
role="article"
>
Expand Down
3 changes: 2 additions & 1 deletion mon-pix/app/components/challenge/item.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { registerDestructor } from '@ember/destroyable';
import { action } from '@ember/object';
import { service } from '@ember/service';
import { ensureSafeComponent } from '@embroider/util';
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit bc71ebe

Please sign in to comment.