REFACTOR: Add themeSettings to the helperContext to avoid a global

This commit is contained in:
Robin Ward 2020-08-14 13:31:43 -04:00
parent 8ac85f54fb
commit 41fd7a8b72
4 changed files with 7 additions and 10 deletions

View File

@ -46,10 +46,8 @@ export function registerHelpers(registry) {
}
let _helperContext;
export function createHelperContext(siteSettings) {
_helperContext = {
siteSettings
};
export function createHelperContext(ctx) {
_helperContext = ctx;
}
// This can be used by a helper to get the SiteSettings. Note you should not

View File

@ -1,5 +1,5 @@
import I18n from "I18n";
import { registerUnbound } from "discourse-common/lib/helpers";
import { helperContext, registerUnbound } from "discourse-common/lib/helpers";
import deprecated from "discourse-common/lib/deprecated";
registerUnbound("theme-i18n", (themeId, key, params) => {
@ -18,7 +18,5 @@ registerUnbound("theme-setting", (themeId, key, hash) => {
{ since: "v2.2.0.beta8", dropFrom: "v2.3.0" }
);
}
return Discourse.__container__
.lookup("service:theme-settings")
.getSetting(themeId, key);
return helperContext().themeSettings.getSetting(themeId, key);
});

View File

@ -16,7 +16,8 @@ export function autoLoadModules(container, registry) {
}
});
let siteSettings = container.lookup("site-settings:main");
createHelperContext(siteSettings);
let themeSettings = container.lookup("service:theme-settings");
createHelperContext({ siteSettings, themeSettings });
registerHelpers(registry);
registerRawHelpers(RawHandlebars, Handlebars);
}

View File

@ -164,7 +164,7 @@ QUnit.testStart(function(ctx) {
Session.resetCurrent();
User.resetCurrent();
resetSite(settings);
createHelperContext(settings);
createHelperContext({ siteSettings: settings });
_DiscourseURL.redirectedTo = null;
_DiscourseURL.redirectTo = function(url) {