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