mirror of
https://github.com/discourse/discourse.git
synced 2025-04-25 01:04:27 +08:00
DEV: Don't nest deferring calls (#30449)
Each case simplified: `next(() => later(() => ...))` -> "wait 0 ms then wait X ms" `next(() => debounce(() => ...))` -> "wait 0 ms then wait X ms (debounced)" `next(() => scheduleAfter("render", ...))` -> "in the next (empty) run loop, do the thing (after a no-op render step)"
This commit is contained in:
parent
db998ee1ab
commit
184ec95d01
@ -1,7 +1,7 @@
|
||||
import Component from "@ember/component";
|
||||
import EmberObject, { action, computed } from "@ember/object";
|
||||
import { getOwner } from "@ember/owner";
|
||||
import { next, schedule, throttle } from "@ember/runloop";
|
||||
import { schedule, throttle } from "@ember/runloop";
|
||||
import { service } from "@ember/service";
|
||||
import { classNameBindings } from "@ember-decorators/component";
|
||||
import { observes, on } from "@ember-decorators/object";
|
||||
@ -803,13 +803,11 @@ export default class ComposerEditor extends Component {
|
||||
|
||||
this.appEvents.trigger(`${this.composerEventPrefix}:will-close`);
|
||||
|
||||
next(() => {
|
||||
// need to wait a bit for the "slide down" transition of the composer
|
||||
discourseLater(
|
||||
() => this.appEvents.trigger(`${this.composerEventPrefix}:closed`),
|
||||
400
|
||||
);
|
||||
});
|
||||
// need to wait a bit for the "slide down" transition of the composer
|
||||
discourseLater(
|
||||
() => this.appEvents.trigger(`${this.composerEventPrefix}:closed`),
|
||||
400
|
||||
);
|
||||
|
||||
preview?.removeEventListener("click", this._handleAltTextCancelButtonClick);
|
||||
preview?.removeEventListener("click", this._handleAltTextEditButtonClick);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { next, schedule } from "@ember/runloop";
|
||||
import { next } from "@ember/runloop";
|
||||
import Service, { service } from "@ember/service";
|
||||
import { bind } from "discourse/lib/decorators";
|
||||
import { isTesting } from "discourse/lib/environment";
|
||||
@ -55,11 +55,7 @@ export default class RouteScrollManager extends Service {
|
||||
|
||||
const scrollLocation = this.historyStore.get(STORE_KEY) || [0, 0];
|
||||
|
||||
next(() =>
|
||||
schedule("afterRender", () =>
|
||||
this.scrollElement.scrollTo(...scrollLocation)
|
||||
)
|
||||
);
|
||||
next(() => this.scrollElement.scrollTo(...scrollLocation));
|
||||
}
|
||||
|
||||
#shouldScroll(routeInfo) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { tracked } from "@glimmer/tracking";
|
||||
import { next, throttle } from "@ember/runloop";
|
||||
import { throttle } from "@ember/runloop";
|
||||
import Service, { service } from "@ember/service";
|
||||
import discourseDebounce from "discourse/lib/debounce";
|
||||
import { bind } from "discourse/lib/decorators";
|
||||
@ -49,11 +49,8 @@ export default class ScrollDirection extends Service {
|
||||
// User hasn't scrolled yet on this route
|
||||
this.lastScrollDirection = UNSCROLLED;
|
||||
|
||||
// Wait for the initial DOM render to be done
|
||||
next(() => {
|
||||
// Then allow a bit of extra time for any DOM shifts to settle
|
||||
discourseDebounce(this.unpause, PAUSE_AFTER_TRANSITION_MS);
|
||||
});
|
||||
// Allow a bit of extra time for any DOM shifts to settle
|
||||
discourseDebounce(this.unpause, PAUSE_AFTER_TRANSITION_MS);
|
||||
}
|
||||
|
||||
@bind
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Component from "@ember/component";
|
||||
import EmberObject, { computed, get } from "@ember/object";
|
||||
import { guidFor } from "@ember/object/internals";
|
||||
import { bind, cancel, next, schedule, throttle } from "@ember/runloop";
|
||||
import { bind, cancel, next, throttle } from "@ember/runloop";
|
||||
import { service } from "@ember/service";
|
||||
import { isEmpty, isNone, isPresent } from "@ember/utils";
|
||||
import {
|
||||
@ -760,13 +760,11 @@ export default class SelectKit extends Component.extend(UtilsMixin) {
|
||||
|
||||
_safeAfterRender(fn) {
|
||||
next(() => {
|
||||
schedule("afterRender", () => {
|
||||
if (!this.element || this.isDestroyed || this.isDestroying) {
|
||||
return;
|
||||
}
|
||||
if (!this.element || this.isDestroyed || this.isDestroying) {
|
||||
return;
|
||||
}
|
||||
|
||||
fn();
|
||||
});
|
||||
fn();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -49,37 +49,33 @@ export default class TextareaInteractor extends EmberObject {
|
||||
@bind
|
||||
blur() {
|
||||
next(() => {
|
||||
schedule("afterRender", () => {
|
||||
this.textarea.blur();
|
||||
});
|
||||
this.textarea.blur();
|
||||
});
|
||||
}
|
||||
|
||||
@bind
|
||||
focus(opts = { ensureAtEnd: false, refreshHeight: true, addText: null }) {
|
||||
next(() => {
|
||||
schedule("afterRender", () => {
|
||||
if (opts.refreshHeight) {
|
||||
this.refreshHeight();
|
||||
}
|
||||
if (opts.refreshHeight) {
|
||||
this.refreshHeight();
|
||||
}
|
||||
|
||||
if (opts.ensureAtEnd) {
|
||||
this.ensureCaretAtEnd();
|
||||
}
|
||||
if (opts.ensureAtEnd) {
|
||||
this.ensureCaretAtEnd();
|
||||
}
|
||||
|
||||
if (this.capabilities.isIpadOS || this.site.mobileView) {
|
||||
return;
|
||||
}
|
||||
if (this.capabilities.isIpadOS || this.site.mobileView) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (opts.addText) {
|
||||
this.textManipulation.addText(
|
||||
this.textManipulation.getSelected(),
|
||||
opts.addText
|
||||
);
|
||||
}
|
||||
if (opts.addText) {
|
||||
this.textManipulation.addText(
|
||||
this.textManipulation.getSelected(),
|
||||
opts.addText
|
||||
);
|
||||
}
|
||||
|
||||
this.textManipulation.blurAndFocus();
|
||||
});
|
||||
this.textManipulation.blurAndFocus();
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user