refactor: 💡 remove usage of ember/runloop & ember-pollster (#2705)

* refactor: 💡 remove usage of ember/runloop & ember-pollster

---------

Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
This commit is contained in:
Lisbet AlvarezandZhihe Li authored and GitHub committed 2025-03-06 12:20:48 -08:00
1 parent e29a83ec25
commit 29bde998ed
23 files changed
+225 -197

No files matched your search

@@ -6,7 +6,6 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { run } from '@ember/runloop';
export default class FormAuthenticateDetailsComponent extends Component {
// =properties
@@ -36,7 +35,7 @@ export default class FormAuthenticateDetailsComponent extends Component {
*/
@action
submit(fn, creds) {
run(() => this.resetPassword());
run(() => fn(creds));
this.resetPassword();
fn(creds);
}
}
@@ -6,7 +6,7 @@
<Hds::Button
@text={{t 'actions.refresh'}}
@color='secondary'
@icon={{if this.isLoading 'loading' 'reload'}}
@icon={{if this.toggleRefresh.isRunning 'loading' 'reload'}}
@disabled={{this.isLoading}}
{{on 'click' this.toggleRefresh}}
{{on 'click' this.toggleRefresh.perform}}
/>
@@ -4,22 +4,13 @@
*/
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { later } from '@ember/runloop';
import { dropTask, timeout } from 'ember-concurrency';
export default class LoadingButton extends Component {
// =actions
@tracked isLoading = false;
// =attributes
@action
async toggleRefresh() {
this.isLoading = true;
try {
await this.args.onClick();
} catch (e) {
console.error('Error while loading data', e);
}
later(() => (this.isLoading = false), 1000);
}
toggleRefresh = dropTask(async () => {
await this.args.onClick();
await timeout(1000);
});
}
+2 -2
View File
@@ -19,10 +19,10 @@ export default class extends Helper {
// Parse the expiration time
const expirationTime = new Date(expiration_time);
// Get the curent time
// Get the current time
const currentTime = this.clockTick.now;
// Calculate the difference in milleseconds
// Calculate the difference in milliseconds
const difference = expirationTime - currentTime;
// Calculate the difference in seconds if the difference is positive
+11 -30
View File
@@ -6,7 +6,7 @@
import Service from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { getOwner } from '@ember/application';
import { next } from '@ember/runloop';
import { task, timeout } from 'ember-concurrency';
export default class ClockTickService extends Service {
// =attributes
@@ -25,9 +25,15 @@ export default class ClockTickService extends Service {
frequency = 1000;
/**
* The timer interval ID
* Updates the value of `now` every `frequency` milliseconds.
*/
#timer;
_tick = task(async () => {
// eslint-disable-next-line no-constant-condition
while (true) {
await timeout(this.frequency);
this.now = Date.now();
}
});
/**
* This service is enabled only in non-test environments.
@@ -45,7 +51,7 @@ export default class ClockTickService extends Service {
*/
constructor() {
super(...arguments);
if (this.enabled) this._start();
if (this.enabled) this._tick.perform();
}
/**
@@ -53,31 +59,6 @@ export default class ClockTickService extends Service {
*/
willDestroy() {
super.willDestroy(...arguments);
this._stop();
}
/**
* Sets up the timer interval, calling `_tick()` every
* `frequency` milliseconds.
*/
_start() {
const self = this;
this.#timer = setInterval(function () {
self._tick();
}, this.frequency);
}
/**
* Clears the timer interval.
*/
_stop() {
clearInterval(this.#timer);
}
/**
* Updates the value of `now` within the next runloop.
*/
_tick() {
next(() => (this.now = Date.now()));
this._tick.cancelAll();
}
}