TrackedObject allows us to reference SiteSettings in autotracking contexts (e.g. JS getters referenced from a Glimmer template) without the need for EmberObject's `get()` function. TrackedObject is backwards-compatible with Ember's legacy reactivity model, so it can be referenced in things like computed properties. Co-authored-by: David Taylor <david@taylorhq.com>
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
import { TrackedObject } from "@ember-compat/tracked-built-ins";
|
|
|
|
const CLIENT_SETTING_TEST_OVERRIDES = {
|
|
title: "QUnit Discourse Tests",
|
|
site_logo_url: "/assets/logo.png",
|
|
site_logo_url: "/assets/logo.png",
|
|
site_logo_small_url: "/assets/logo-single.png",
|
|
site_mobile_logo_url: "",
|
|
site_favicon_url: "/images/discourse-logo-sketch-small.png",
|
|
enable_twitter_logins: true,
|
|
enable_facebook_logins: true,
|
|
enable_github_logins: true,
|
|
authorized_extensions: "jpg|jpeg|png|gif|heic|heif|webp|svg|txt|ico|yml",
|
|
anon_polling_interval: 30000,
|
|
flush_timings_secs: 5,
|
|
};
|
|
|
|
// Note, CLIENT_SITE_SETTINGS_WITH_DEFAULTS is generated by the site-settings-plugin,
|
|
// writing to test-site-settings.js via the ember-cli-build pipeline.
|
|
const ORIGINAL_CLIENT_SITE_SETTINGS = {
|
|
// eslint-disable-next-line no-undef
|
|
...CLIENT_SITE_SETTINGS_WITH_DEFAULTS,
|
|
...CLIENT_SETTING_TEST_OVERRIDES,
|
|
};
|
|
|
|
let siteSettings;
|
|
|
|
export function currentSettings() {
|
|
return siteSettings;
|
|
}
|
|
|
|
export function mergeSettings(other) {
|
|
for (const key of Object.keys(other)) {
|
|
siteSettings[key] = other[key];
|
|
}
|
|
|
|
return siteSettings;
|
|
}
|
|
|
|
export function resetSettings() {
|
|
siteSettings = new TrackedObject(ORIGINAL_CLIENT_SITE_SETTINGS);
|
|
return siteSettings;
|
|
}
|