From b469addd296e3f12694c2aa99515e07a88be9c07 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Mon, 3 Nov 2025 14:52:12 -0800 Subject: [PATCH] Remove withGetter --- src/app/core/commands.ts | 7 +-- src/app/core/state.ts | 109 +++++++++++++++++---------------------- 2 files changed, 51 insertions(+), 65 deletions(-) diff --git a/src/app/core/commands.ts b/src/app/core/commands.ts index 2785c666..d8e9fa48 100644 --- a/src/app/core/commands.ts +++ b/src/app/core/commands.ts @@ -103,6 +103,7 @@ import { DEFAULT_BLOSSOM_SERVERS, userSpaceUrls, userSettingsValues, + getSetting, userInboxRelays, userGroupSelections, } from "@app/core/state" @@ -549,7 +550,7 @@ export const createDmAlert = async () => { // Settings export const makeSettings = async (params: Partial) => { - const json = JSON.stringify({...userSettingsValues.get(), ...params}) + const json = JSON.stringify({...get(userSettingsValues), ...params}) const content = await signer.get().nip44.encrypt(pubkey.get()!, json) const tags = [["d", SETTINGS]] @@ -560,10 +561,10 @@ export const publishSettings = async (params: Partial) => publishThunk({event: await makeSettings(params), relays: Router.get().FromUser().getUrls()}) export const addTrustedRelay = async (url: string) => - publishSettings({trusted_relays: append(url, userSettingsValues.get().trusted_relays)}) + publishSettings({trusted_relays: append(url, getSetting("trusted_relays"))}) export const removeTrustedRelay = async (url: string) => - publishSettings({trusted_relays: remove(url, userSettingsValues.get().trusted_relays)}) + publishSettings({trusted_relays: remove(url, getSetting("trusted_relays"))}) // Join request diff --git a/src/app/core/state.ts b/src/app/core/state.ts index 6918b7b6..3852220e 100644 --- a/src/app/core/state.ts +++ b/src/app/core/state.ts @@ -36,14 +36,7 @@ import { SocketEvent, netContext, } from "@welshman/net" -import { - collection, - custom, - throttled, - deriveEvents, - deriveEventsMapped, - withGetter, -} from "@welshman/store" +import {collection, custom, throttled, deriveEvents, deriveEventsMapped} from "@welshman/store" import {isKindFeed, findFeed} from "@welshman/feeds" import { ALERT_ANDROID, @@ -241,31 +234,29 @@ export const deriveEvent = (idOrAddress: string, hints: string[] = []) => { ) } -export const getUrlsForEvent = withGetter( - derived([trackerStore, thunks], ([$tracker, $thunks]) => { - const getThunksByEventId = memoize(() => { - const thunksByEventId = new Map() +export const getUrlsForEvent = derived([trackerStore, thunks], ([$tracker, $thunks]) => { + const getThunksByEventId = memoize(() => { + const thunksByEventId = new Map() - for (const thunk of $thunks) { - pushToMapKey(thunksByEventId, thunk.event.id, thunk) - } - - return thunksByEventId - }) - - return (id: string) => { - const urls = Array.from($tracker.getRelays(id)) - - for (const thunk of getThunksByEventId().get(id) || []) { - for (const url of thunk.options.relays) { - urls.push(url) - } - } - - return uniq(urls) + for (const thunk of $thunks) { + pushToMapKey(thunksByEventId, thunk.event.id, thunk) } - }), -) + + return thunksByEventId + }) + + return (id: string) => { + const urls = Array.from($tracker.getRelays(id)) + + for (const thunk of getThunksByEventId().get(id) || []) { + for (const url of thunk.options.relays) { + urls.push(url) + } + } + + return uniq(urls) + } +}) export const getEventsForUrl = (url: string, filters: Filter[]) => { const ids = uniq([ @@ -383,15 +374,13 @@ export const userSettings = makeUserData({ export const loadUserSettings = makeUserLoader(loadSettings) -export const userSettingsValues = withGetter( - derived(userSettings, $s => $s?.values || defaultSettings), -) +export const userSettingsValues = derived(userSettings, $s => $s?.values || defaultSettings) -export const getSetting = (key: keyof Settings["values"]) => userSettingsValues.get()[key] as T +export const getSetting = (key: keyof Settings["values"]) => get(userSettingsValues)[key] as T // Relays sending events with empty signatures that the user has to choose to trust -export const relaysPendingTrust = withGetter(writable([])) +export const relaysPendingTrust = writable([]) // Relays that mostly send restricted responses to requests and events @@ -416,21 +405,19 @@ export type Alert = { tags: string[][] } -export const alerts = withGetter( - deriveEventsMapped(repository, { - filters: [{kinds: [ALERT_EMAIL, ALERT_WEB, ALERT_IOS, ALERT_ANDROID]}], - itemToEvent: item => item.event, - eventToItem: async event => { - const $signer = signer.get() +export const alerts = deriveEventsMapped(repository, { + filters: [{kinds: [ALERT_EMAIL, ALERT_WEB, ALERT_IOS, ALERT_ANDROID]}], + itemToEvent: item => item.event, + eventToItem: async event => { + const $signer = signer.get() - if ($signer) { - const tags = parseJson(await decrypt($signer, NOTIFIER_PUBKEY, event.content)) + if ($signer) { + const tags = parseJson(await decrypt($signer, NOTIFIER_PUBKEY, event.content)) - return {event, tags} - } - }, - }), -) + return {event, tags} + } + }, +}) export const getAlertFeed = (alert: Alert) => tryCatch(() => JSON.parse(getTagValue("feed", alert.tags)!)) @@ -450,21 +437,19 @@ export type AlertStatus = { tags: string[][] } -export const alertStatuses = withGetter( - deriveEventsMapped(repository, { - filters: [{kinds: [ALERT_STATUS]}], - itemToEvent: item => item.event, - eventToItem: async event => { - const $signer = signer.get() +export const alertStatuses = deriveEventsMapped(repository, { + filters: [{kinds: [ALERT_STATUS]}], + itemToEvent: item => item.event, + eventToItem: async event => { + const $signer = signer.get() - if ($signer) { - const tags = parseJson(await decrypt($signer, NOTIFIER_PUBKEY, event.content)) + if ($signer) { + const tags = parseJson(await decrypt($signer, NOTIFIER_PUBKEY, event.content)) - return {event, tags} - } - }, - }), -) + return {event, tags} + } + }, +}) export const deriveAlertStatus = (address: string) => derived(alertStatuses, statuses => statuses.find(s => getTagValue("d", s.event.tags) === address))