Skip to content

Commit

Permalink
clean up reactivity code
Browse files Browse the repository at this point in the history
  • Loading branch information
twnlink committed Jan 31, 2024
1 parent b02ecc6 commit fa91d13
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/api/themes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { store } from "voby";
import { appendStyle, createPersistentObject, parseManifest } from "./utils.js";

export const [themesStore, themesStoreReady] = createPersistentObject("NEPTUNE_THEMES", true);

let updateThemeStyle = appendStyle("");

// Not sure why this didn't work previously?
store.on(themesStore, reloadThemes)

function reloadThemes() {
updateThemeStyle(themesStore.filter(t => t.enabled).map((t) => `@import url("${t.url}")`).join(";"));
}
Expand All @@ -13,16 +17,11 @@ export function removeTheme(url) {
themesStore.findIndex((t) => t.url == url),
1,
);

// Spamming this everywhere sucks but we'll get reactive objects working a little bit better in a bit.
reloadThemes();
}

export function toggleTheme(url) {
const theme = themesStore.find((t) => t.url == url);
theme.enabled = !theme.enabled;

reloadThemes();
}

export async function importTheme(url, enabled = true) {
Expand All @@ -46,6 +45,4 @@ export async function importTheme(url, enabled = true) {
enabled,
url,
});

reloadThemes();
}

0 comments on commit fa91d13

Please sign in to comment.