Skip to content

Commit 1107bc3

Browse files
authored
Remove ember/runloop from addon (#628)
* Remove ember/runloop from addon * Fix lint * Use queueMicrotask instead runloop * Remove eslint run loop disable * Remove all ember runloop in tests app
1 parent 6354cd1 commit 1107bc3

10 files changed

Lines changed: 90 additions & 136 deletions

File tree

demo-app/app.gts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@ export class App extends EmberApp {
4949
};
5050
}
5151

52-
Router.map(function () {});
52+
Router.map(function () {
53+
this.route('helpers-testing');
54+
});

eslint.config.mjs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ export default defineConfig([
8787
},
8888
ember.configs.gts,
8989
],
90-
rules: {
91-
'ember/no-runloop': 0,
92-
},
9390
},
9491
{
9592
files: ['src/**/*'],
@@ -124,7 +121,6 @@ export default defineConfig([
124121
'@typescript-eslint/no-unsafe-return': 'off',
125122
'@typescript-eslint/no-unsafe-call': 'off',
126123
'@typescript-eslint/no-unsafe-member-access': 'off',
127-
'ember/no-runloop': 0,
128124
},
129125
},
130126
/**

src/components/power-calendar-multiple/days.gts

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Component from '@glimmer/component';
22
import { tracked } from '@glimmer/tracking';
33
import { action } from '@ember/object';
4-
import { scheduleOnce } from '@ember/runloop';
54
import { service } from '@ember/service';
65
import {
76
add,
@@ -153,17 +152,16 @@ export default class PowerCalendarMultipleDays extends Component<PowerCalendarMu
153152
// Actions
154153
@action
155154
handleDayFocus(e: FocusEvent): void {
156-
scheduleOnce(
157-
'actions',
158-
this,
159-
this._updateFocused.bind(this),
160-
(e.target as HTMLElement).dataset['date'],
161-
);
155+
queueMicrotask(() => {
156+
this._updateFocused((e.target as HTMLElement).dataset['date']);
157+
});
162158
}
163159

164160
@action
165161
handleDayBlur(): void {
166-
scheduleOnce('actions', this, this._updateFocused.bind(this), null);
162+
queueMicrotask(() => {
163+
this._updateFocused(null);
164+
});
167165
}
168166

169167
@action
@@ -210,36 +208,29 @@ export default class PowerCalendarMultipleDays extends Component<PowerCalendarMu
210208
}
211209

212210
this.focusedId = day.id;
213-
scheduleOnce(
214-
'afterRender',
215-
this,
216-
focusDate,
217-
this.args.calendar.uniqueId,
218-
this.focusedId ?? '',
219-
);
211+
queueMicrotask(() => {
212+
focusDate(this.args.calendar.uniqueId, this.focusedId ?? '');
213+
});
220214
}
221215

222216
@action
223217
handleClick(e: MouseEvent) {
224218
handleClick(e, this.days, this.args.calendar);
225219
}
226220

227-
setup = modifier(
228-
() => {
229-
if (this.didSetup) {
230-
return;
231-
}
221+
setup = modifier(() => {
222+
if (this.didSetup) {
223+
return;
224+
}
232225

233-
this.didSetup = true;
226+
this.didSetup = true;
234227

228+
if (this.args.autofocus) {
235229
if (this.args.autofocus) {
236-
scheduleOnce('afterRender', this, this.initialFocus.bind(this));
230+
queueMicrotask(() => this.initialFocus());
237231
}
238-
},
239-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
240-
// @ts-ignore
241-
{ eager: false },
242-
);
232+
}
233+
});
243234

244235
initialFocus() {
245236
const activeDay = this.days.find((x) => x.isSelected && !x.isDisabled);
@@ -288,13 +279,9 @@ export default class PowerCalendarMultipleDays extends Component<PowerCalendarMu
288279
this.focusedId = formatDate(date, 'YYYY-MM-DD');
289280

290281
if (step !== 0) {
291-
scheduleOnce(
292-
'afterRender',
293-
this,
294-
focusDate,
295-
this.args.calendar.uniqueId,
296-
this.focusedId ?? '',
297-
);
282+
queueMicrotask(() => {
283+
focusDate(this.args.calendar.uniqueId, this.focusedId ?? '');
284+
});
298285
} else {
299286
focusDate(this.args.calendar.uniqueId, this.focusedId ?? '');
300287
}

src/components/power-calendar-range/days.gts

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Component from '@glimmer/component';
22
import { tracked } from '@glimmer/tracking';
33
import { action } from '@ember/object';
4-
import { scheduleOnce } from '@ember/runloop';
54
import { service } from '@ember/service';
65
import emberPowerCalendarDayClasses, {
76
type TDayClass,
@@ -141,17 +140,16 @@ export default class PowerCalendarRangeDays extends Component<PowerCalendarRange
141140
// Actions
142141
@action
143142
handleDayFocus(e: FocusEvent): void {
144-
scheduleOnce(
145-
'actions',
146-
this,
147-
this._updateFocused.bind(this),
148-
(e.target as HTMLElement).dataset['date'],
149-
);
143+
queueMicrotask(() => {
144+
this._updateFocused((e.target as HTMLElement).dataset['date']);
145+
});
150146
}
151147

152148
@action
153149
handleDayBlur(): void {
154-
scheduleOnce('actions', this, this._updateFocused.bind(this), null);
150+
queueMicrotask(() => {
151+
this._updateFocused(null);
152+
});
155153
}
156154

157155
@action
@@ -200,13 +198,9 @@ export default class PowerCalendarRangeDays extends Component<PowerCalendarRange
200198
}
201199

202200
this.focusedId = day.id;
203-
scheduleOnce(
204-
'afterRender',
205-
this,
206-
focusDate,
207-
this.args.calendar.uniqueId,
208-
this.focusedId ?? '',
209-
);
201+
queueMicrotask(() => {
202+
focusDate(this.args.calendar.uniqueId, this.focusedId ?? '');
203+
});
210204
}
211205

212206
@action
@@ -234,22 +228,19 @@ export default class PowerCalendarRangeDays extends Component<PowerCalendarRange
234228
this.lastKeyDownWasSpace = false;
235229
}
236230

237-
setup = modifier(
238-
() => {
239-
if (this.didSetup) {
240-
return;
241-
}
231+
setup = modifier(() => {
232+
if (this.didSetup) {
233+
return;
234+
}
242235

243-
this.didSetup = true;
236+
this.didSetup = true;
244237

238+
if (this.args.autofocus) {
245239
if (this.args.autofocus) {
246-
scheduleOnce('afterRender', this, this.initialFocus.bind(this));
240+
queueMicrotask(() => this.initialFocus());
247241
}
248-
},
249-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
250-
// @ts-ignore
251-
{ eager: false },
252-
);
242+
}
243+
});
253244

254245
initialFocus() {
255246
const activeDay = this.days.find((x) => x.isSelected && !x.isDisabled);
@@ -298,13 +289,9 @@ export default class PowerCalendarRangeDays extends Component<PowerCalendarRange
298289
this.focusedId = formatDate(date, 'YYYY-MM-DD');
299290

300291
if (step !== 0) {
301-
scheduleOnce(
302-
'afterRender',
303-
this,
304-
focusDate,
305-
this.args.calendar.uniqueId,
306-
this.focusedId ?? '',
307-
);
292+
queueMicrotask(() => {
293+
focusDate(this.args.calendar.uniqueId, this.focusedId ?? '');
294+
});
308295
} else {
309296
focusDate(this.args.calendar.uniqueId, this.focusedId ?? '');
310297
}

src/components/power-calendar/days.gts

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Component from '@glimmer/component';
22
import { tracked } from '@glimmer/tracking';
33
import { action } from '@ember/object';
4-
import { scheduleOnce } from '@ember/runloop';
54
import { modifier } from 'ember-modifier';
65
import { service } from '@ember/service';
76
import {
@@ -146,17 +145,16 @@ export default class PowerCalendarDays extends Component<PowerCalendarDaysSignat
146145
// Actions
147146
@action
148147
handleDayFocus(e: FocusEvent): void {
149-
scheduleOnce(
150-
'actions',
151-
this,
152-
this._updateFocused.bind(this),
153-
(e.target as HTMLElement).dataset['date'],
154-
);
148+
queueMicrotask(() => {
149+
this._updateFocused((e.target as HTMLElement).dataset['date']);
150+
});
155151
}
156152

157153
@action
158154
handleDayBlur(): void {
159-
scheduleOnce('actions', this, this._updateFocused.bind(this), null);
155+
queueMicrotask(() => {
156+
this._updateFocused(null);
157+
});
160158
}
161159

162160
@action
@@ -203,36 +201,29 @@ export default class PowerCalendarDays extends Component<PowerCalendarDaysSignat
203201
}
204202

205203
this.focusedId = day.id;
206-
scheduleOnce(
207-
'afterRender',
208-
this,
209-
focusDate,
210-
this.args.calendar.uniqueId,
211-
this.focusedId ?? '',
212-
);
204+
queueMicrotask(() => {
205+
focusDate(this.args.calendar.uniqueId, this.focusedId ?? '');
206+
});
213207
}
214208

215209
@action
216210
handleClick(e: MouseEvent) {
217211
handleClick(e, this.days, this.args.calendar);
218212
}
219213

220-
setup = modifier(
221-
() => {
222-
if (this.didSetup) {
223-
return;
224-
}
214+
setup = modifier(() => {
215+
if (this.didSetup) {
216+
return;
217+
}
225218

226-
this.didSetup = true;
219+
this.didSetup = true;
227220

221+
if (this.args.autofocus) {
228222
if (this.args.autofocus) {
229-
scheduleOnce('afterRender', this, this.initialFocus.bind(this));
223+
queueMicrotask(() => this.initialFocus());
230224
}
231-
},
232-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
233-
// @ts-ignore
234-
{ eager: false },
235-
);
225+
}
226+
});
236227

237228
initialFocus() {
238229
const activeDay = this.days.find((x) => x.isSelected && !x.isDisabled);
@@ -281,13 +272,9 @@ export default class PowerCalendarDays extends Component<PowerCalendarDaysSignat
281272
this.focusedId = formatDate(date, 'YYYY-MM-DD');
282273

283274
if (step !== 0) {
284-
scheduleOnce(
285-
'afterRender',
286-
this,
287-
focusDate,
288-
this.args.calendar.uniqueId,
289-
this.focusedId ?? '',
290-
);
275+
queueMicrotask(() => {
276+
focusDate(this.args.calendar.uniqueId, this.focusedId ?? '');
277+
});
291278
} else {
292279
focusDate(this.args.calendar.uniqueId, this.focusedId ?? '');
293280
}

tests/integration/components/power-calendar-multiple-test.gts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { module, test } from 'qunit';
22
import { setupRenderingTest } from 'ember-qunit';
33
import { render, click, type TestContext } from '@ember/test-helpers';
4-
import { run } from '@ember/runloop';
54
import { isSame, formatDate } from '#src/test-support/helpers.ts';
65
import PowerCalendarMultiple from '#src/components/power-calendar-multiple.gts';
76
import { on } from '@ember/modifier';
@@ -334,7 +333,8 @@ module('Integration | Component | <PowerCalendarMultiple>', function (hooks) {
334333
.dom('.ember-power-calendar-day[data-date="2013-10-23"]')
335334
.isDisabled('The 23rd is disabled');
336335

337-
run(() => this.set('disabledDates', [new Date(2013, 9, 22)]));
336+
this.set('disabledDates', [new Date(2013, 9, 22)]);
337+
338338
assert
339339
.dom('.ember-power-calendar-day[data-date="2013-10-14"]')
340340
.isNotDisabled('The 14th is enabled');

tests/integration/components/power-calendar-range-test.gts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { module, test } from 'qunit';
22
import { setupRenderingTest } from 'ember-qunit';
33
import { render, click } from '@ember/test-helpers';
4-
import { run } from '@ember/runloop';
54
import PowerCalendarRange from '#src/components/power-calendar-range.gts';
65
import { on } from '@ember/modifier';
76
import { fn } from '@ember/helper';
@@ -557,18 +556,18 @@ module('Integration | Component | <PowerCalendarRange>', function (hooks) {
557556
assert
558557
.dom('.formatted-min-range')
559558
.hasText('86400000', 'the default minRange is one day');
560-
run(() => this.set('minRange', 3));
559+
this.set('minRange', 3);
561560
assert
562561
.dom('.formatted-min-range')
563562
.hasText(
564563
'259200000',
565564
'when passed a number, it is interpreted as number of days',
566565
);
567-
run(() => this.set('minRange', '1 week'));
566+
this.set('minRange', '1 week');
568567
assert
569568
.dom('.formatted-min-range')
570569
.hasText('604800000', 'it can regognize humanized durations');
571-
run(() => this.set('minRange', '1m'));
570+
this.set('minRange', '1m');
572571
assert
573572
.dom('.formatted-min-range')
574573
.hasText(

0 commit comments

Comments
 (0)