mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Reduce async/indirection in site-header (#30011)
This commit is contained in:
parent
fa4a37fd7d
commit
bf3e75ca70
@ -65,7 +65,7 @@ export default class GlimmerSiteHeader extends Component {
|
|||||||
this._itsatrap = null;
|
this._itsatrap = null;
|
||||||
|
|
||||||
window.removeEventListener("scroll", this._recalculateHeaderOffset);
|
window.removeEventListener("scroll", this._recalculateHeaderOffset);
|
||||||
this._resizeObserver?.disconnect();
|
this._resizeObserver.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
get dropDownHeaderEnabled() {
|
get dropDownHeaderEnabled() {
|
||||||
@ -84,8 +84,12 @@ export default class GlimmerSiteHeader extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@bind
|
@debounce(DEBOUNCE_HEADER_DELAY)
|
||||||
updateOffsets() {
|
_recalculateHeaderOffset() {
|
||||||
|
if (this.isDestroying || this.isDestroyed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// clamping to 0 to prevent negative values (hello, Safari)
|
// clamping to 0 to prevent negative values (hello, Safari)
|
||||||
const headerWrapBottom = Math.max(
|
const headerWrapBottom = Math.max(
|
||||||
0,
|
0,
|
||||||
@ -122,16 +126,6 @@ export default class GlimmerSiteHeader extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@debounce(DEBOUNCE_HEADER_DELAY)
|
|
||||||
_recalculateHeaderOffset() {
|
|
||||||
this._scheduleUpdateOffsets();
|
|
||||||
}
|
|
||||||
|
|
||||||
@bind
|
|
||||||
_scheduleUpdateOffsets() {
|
|
||||||
schedule("afterRender", this.updateOffsets);
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
setupHeader() {
|
setupHeader() {
|
||||||
this.appEvents.on("user-menu:rendered", this, this.animateMenu);
|
this.appEvents.on("user-menu:rendered", this, this.animateMenu);
|
||||||
@ -158,10 +152,7 @@ export default class GlimmerSiteHeader extends Component {
|
|||||||
const dirs = ["up", "down"];
|
const dirs = ["up", "down"];
|
||||||
this._itsatrap.bind(dirs, (e) => this._handleArrowKeysNav(e));
|
this._itsatrap.bind(dirs, (e) => this._handleArrowKeysNav(e));
|
||||||
|
|
||||||
this._resizeObserver = new ResizeObserver(() => {
|
this._resizeObserver = new ResizeObserver(this._recalculateHeaderOffset);
|
||||||
this._recalculateHeaderOffset();
|
|
||||||
});
|
|
||||||
|
|
||||||
this._resizeObserver.observe(document.querySelector(".discourse-root"));
|
this._resizeObserver.observe(document.querySelector(".discourse-root"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user