feat: migrate pre-request script, test script, settings to nuxt composition

This commit is contained in:
liyasthomas
2021-07-21 10:50:20 +05:30
parent d4234f0837
commit 22772ac10f
12 changed files with 333 additions and 218 deletions

View File

@@ -1,8 +1,10 @@
import { pluck, distinctUntilChanged } from "rxjs/operators"
import has from "lodash/has"
import { Observable } from "rxjs"
import { Ref } from "@nuxtjs/composition-api"
import DispatchingStore, { defineDispatchers } from "./DispatchingStore"
import type { KeysMatching } from "~/types/ts-utils"
import { useStream } from "~/helpers/utils/composables"
export const HoppBgColors = ["system", "light", "dark", "black"] as const
@@ -43,6 +45,7 @@ export type SettingsType = {
BG_COLOR: HoppBgColor
TELEMETRY_ENABLED: boolean
SHORTCUTS_INDICATOR_ENABLED: boolean
HIDE_NAVBAR: boolean
}
export const defaultSettings: SettingsType = {
@@ -66,6 +69,7 @@ export const defaultSettings: SettingsType = {
BG_COLOR: "system",
TELEMETRY_ENABLED: true,
SHORTCUTS_INDICATOR_ENABLED: false,
HIDE_NAVBAR: false,
}
const validKeys = Object.keys(defaultSettings)
@@ -152,3 +156,21 @@ export function applySetting<K extends keyof SettingsType>(
},
})
}
export function useSetting<K extends keyof SettingsType>(
settingKey: K
): Ref<SettingsType[K]> {
return useStream(
settingsStore.subject$.pipe(pluck(settingKey), distinctUntilChanged()),
settingsStore.value[settingKey],
(value: SettingsType[K]) => {
settingsStore.dispatch({
dispatcher: "applySetting",
payload: {
settingKey,
value,
},
})
}
)
}