DEV: Defer creation of extraNavItems until they are required

This also means that each list view gets a fresh set of ExtraNavItems.
This commit is contained in:
Daniel Waterworth 2019-11-13 13:38:41 +00:00
parent e00ec22582
commit a7dd31496e
1 changed files with 8 additions and 8 deletions

View File

@ -95,7 +95,7 @@ const ExtraNavItem = NavItem.extend({
NavItem.reopenClass({
extraArgsCallbacks: [],
customNavItemHrefs: [],
extraNavItems: [],
extraNavItemDescriptors: [],
// create a nav item from the text, will return null if there is not valid nav item for this particular text
fromText(text, opts) {
@ -159,10 +159,12 @@ NavItem.reopenClass({
i => i !== null && !(category && i.get("name").indexOf("categor") === 0)
);
const extraItems = NavItem.extraNavItems.filter(item => {
if (!item.customFilter) return true;
return item.customFilter(category, args);
});
const extraItems = NavItem.extraNavItemDescriptors
.map(descriptor => ExtraNavItem.create(descriptor))
.filter(item => {
if (!item.customFilter) return true;
return item.customFilter(category, args);
});
let forceActive = false;
@ -218,9 +220,7 @@ export function customNavItemHref(cb) {
}
export function addNavItem(item) {
const navItem = ExtraNavItem.create(item);
NavItem.extraNavItems.push(navItem);
return navItem;
NavItem.extraNavItemDescriptors.push(item);
}
Object.defineProperty(Discourse, "NavItem", {