fixed changing editor theme #300

This commit is contained in:
Jan Prochazka
2022-07-14 19:22:37 +02:00
parent bef8cdbee4
commit 1f8ef8e20e
3 changed files with 28 additions and 14 deletions

View File

@@ -29,7 +29,11 @@ export function writableWithStorage<T>(defaultValue: T, storageName) {
}
export function writableSettingsValue<T>(defaultValue: T, storageName) {
const res = derived(useSettings(), $settings => ($settings || {})[storageName] ?? defaultValue);
const res = derived(useSettings(), $settings => {
const obj = $settings || {};
// console.log('GET SETTINGS', $settings, storageName, obj[storageName]);
return obj[storageName] ?? defaultValue;
});
return {
...res,
set: value => apiCall('config/update-settings', { [storageName]: value }),

View File

@@ -189,25 +189,29 @@ async function getCore(loader, args) {
function useCore(loader, args) {
const { url, params, reloadTrigger, transform, onLoaded } = loader(args);
const cacheKey = stableStringify({ url, ...params });
let closed = false;
let openedCount = 0;
return {
subscribe: onChange => {
async function handleReload() {
const res = await getCore(loader, args);
if (!closed) {
if (openedCount > 0) {
onChange(res);
}
}
openedCount += 1;
handleReload();
if (reloadTrigger) {
subscribeCacheChange(reloadTrigger, cacheKey, handleReload);
return () => {
closed = true;
openedCount -= 1;
unsubscribeCacheChange(reloadTrigger, cacheKey, handleReload);
};
} else {
return () => {
openedCount -= 1;
};
}
},
};