Skip to content

Commit

Permalink
refactor(frontend): dont use did-insert
Browse files Browse the repository at this point in the history
  • Loading branch information
c0rydoras committed Aug 20, 2024
1 parent a5ac207 commit 7a41b0b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 31 deletions.
14 changes: 1 addition & 13 deletions frontend/app/components/sy-checkbox/component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { action } from "@ember/object";
import { guidFor } from "@ember/object/internals";
import Component from "@glimmer/component";

Expand All @@ -13,17 +12,6 @@ export default class SyCheckbox extends Component {
constructor(...args) {
super(...args);

this._checkboxElementId = guidFor(this);
}

get checkboxElementId() {
return this._checkboxElementId;
}

@action
handleCheckBox(element) {
if (this.args.checked === null) {
element.indeterminate = true;
}
this.checkboxElementId = guidFor(this);
}
}
3 changes: 1 addition & 2 deletions frontend/app/components/sy-checkbox/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
id={{this.checkboxElementId}}
checked={{@checked}}
disabled={{@disabled}}
indeterminate={{eq @checked null}}
{{on "change" (pick "target.checked" (optional @onChange))}}
{{!-- template-lint-disable no-at-ember-render-modifiers --}}
{{did-insert this.handleCheckBox}}
/>
<label for={{this.checkboxElementId}} title={{@title}}>
{{#if (has-block)}}
Expand Down
15 changes: 5 additions & 10 deletions frontend/app/components/sy-modal/overlay/component.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { registerDestructor } from "@ember/destroyable";
import { action } from "@ember/object";
import { guidFor } from "@ember/object/internals";
import Component from "@glimmer/component";

export default class SyModalOverlay extends Component {
@action
setupClickHandler(element) {
this.element = element;

element.addEventListener("click", this.handleClick);
constructor(...args) {
super(...args);

registerDestructor(this, () => {
element.removeEventListener("click", this.handleClick);
});
this.id = guidFor(this);
}

@action
handleClick(e) {
if (e.target === this.element) {
if (e.target.id === this.id) {
this.args.onClose();
}
}
Expand Down
5 changes: 3 additions & 2 deletions frontend/app/components/sy-modal/overlay/template.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<div
class="modal modal-overlay {{if @visible 'modal--visible'}}"
{{!-- template-lint-disable no-at-ember-render-modifiers --}}
{{did-insert this.setupClickHandler}}
id={{this.id}}
{{!-- template-lint-disable no-invalid-interactive --}}
{{on "click" this.handleClick}}
>
{{yield}}
</div>
9 changes: 7 additions & 2 deletions frontend/app/components/timed-clock/component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { setProperties } from "@ember/object";
import { scheduleOnce } from "@ember/runloop";
import { isTesting, macroCondition } from "@embroider/macros";
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
Expand All @@ -20,17 +21,21 @@ export default class TimedClock extends Component {
setProperties(this, { second, minute, hour });
}

constructor(...args) {
super(...args);

scheduleOnce("actions", this.timer, "perform");
}

@task
*timer() {
for (;;) {
this._update();

/* istanbul ignore else */
if (macroCondition(isTesting())) {
return;
}

/* istanbul ignore next */
yield timeout(1000);
}
}
Expand Down
2 changes: 0 additions & 2 deletions frontend/app/components/timed-clock/template.hbs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{{!-- template-lint-disable no-at-ember-render-modifiers --}}
<svg
class="timed-clock"
viewBox="0 0 512 512"
width="100%"
height="100%"
{{style --clock-size=(concat (or @clockSize 50) "px")}}
{{did-insert (perform this.timer)}}
>
<circle class="circle" r="240" cx="256" cy="256" stroke-width="20" />
<line
Expand Down

0 comments on commit 7a41b0b

Please sign in to comment.