mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
PERF: Remove custom Sidebar::SectionLinkTo implementation
This custom implementation was extending from `Ember.LinkComponent`, which is a legacy 'classic component' implementation of `<LinkTo`. Our current version of Ember includes a native glimmer implementation of LinkTo which should be much faster. The patch we introduced was to set the 5th argument to `routing.isActiveForRoute` to `false`. In our current version of Ember, `isActiveForRoute` only takes 4 arguments, so this override is essentially a no-op. The change was made in https://github.com/emberjs/ember.js/commit/56af48bb41 (first released in Ember 3.24).
This commit is contained in:
parent
1a653d2ce9
commit
18e1f0e5b2
@ -1,51 +0,0 @@
|
||||
import Ember from "ember";
|
||||
|
||||
export default class SidebarSectionLinkTo extends Ember.LinkComponent {
|
||||
// Overriding the private function here because the behavior of the component when used with the `current-when`
|
||||
// attribute does not seem to follow what was mentioned in the docs: "A link will be active if current-when is true or
|
||||
// the current route is the route this link would transition to". When the `current-when` attribute is used, the
|
||||
// `route` and `query` attributes are ignored which is not what we want. In addition, we're stuck on Ember 3.15 at
|
||||
// the moment and are awaiting the upgrade to the latest supported Ember version before I can determine if this is a
|
||||
// bug and report it as such.
|
||||
_isActive(routerState) {
|
||||
if (this.loading) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let currentWhen = this["current-when"];
|
||||
|
||||
if (typeof currentWhen === "boolean") {
|
||||
return currentWhen;
|
||||
}
|
||||
|
||||
let isCurrentWhenSpecified = Boolean(currentWhen);
|
||||
|
||||
if (isCurrentWhenSpecified) {
|
||||
currentWhen = currentWhen.split(" ");
|
||||
} else {
|
||||
currentWhen = [this._route];
|
||||
}
|
||||
|
||||
let { _models: models, _query: query, _routing: routing } = this;
|
||||
|
||||
for (let i = 0; i < currentWhen.length; i++) {
|
||||
if (
|
||||
routing.isActiveForRoute(
|
||||
models,
|
||||
query,
|
||||
currentWhen[i],
|
||||
routerState,
|
||||
// **custom code override start**
|
||||
// we always want query params to be considered
|
||||
false
|
||||
// isCurrentWhenSpecified
|
||||
// **custom code override end**
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -25,13 +25,13 @@
|
||||
</span>
|
||||
</a>
|
||||
{{else}}
|
||||
<Sidebar::SectionLinkTo
|
||||
@class={{this.classNames}}
|
||||
<LinkTo
|
||||
class={{this.classNames}}
|
||||
@route={{@route}}
|
||||
@query={{@query}}
|
||||
@models={{this.models}}
|
||||
@current-when={{@currentWhen}}
|
||||
@title={{@title}}
|
||||
title={{@title}}
|
||||
>
|
||||
|
||||
<Sidebar::SectionLinkPrefix
|
||||
@ -86,7 +86,7 @@
|
||||
</button>
|
||||
</span>
|
||||
{{/if}}
|
||||
</Sidebar::SectionLinkTo>
|
||||
</LinkTo>
|
||||
{{/if}}
|
||||
</li>
|
||||
{{/if}}
|
Loading…
Reference in New Issue
Block a user