From 369a89dc601ce89338d51351ee2d25f8598fa5dc Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Wed, 29 Jan 2025 10:08:58 -0800 Subject: [PATCH] Add abortThunk, bump versions --- packages/app/package.json | 4 ++-- packages/app/src/thunk.ts | 8 +++++++- packages/lib/package.json | 4 ++-- packages/lib/src/Tools.ts | 8 +++++++- packages/store/package.json | 2 +- packages/util/package.json | 2 +- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/packages/app/package.json b/packages/app/package.json index 8b3a8a0..77a9703 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/app", - "version": "0.0.41", + "version": "0.0.42", "author": "hodlbod", "license": "MIT", "description": "A collection of svelte stores for use in building nostr client applications.", @@ -29,7 +29,7 @@ "@types/throttle-debounce": "^5.0.2", "@welshman/dvm": "~0.0.13", "@welshman/feeds": "~0.0.30", - "@welshman/lib": "~0.0.37", + "@welshman/lib": "~0.0.39", "@welshman/net": "~0.0.46", "@welshman/signer": "~0.0.19", "@welshman/store": "~0.0.15", diff --git a/packages/app/src/thunk.ts b/packages/app/src/thunk.ts index 49c0180..9534134 100644 --- a/packages/app/src/thunk.ts +++ b/packages/app/src/thunk.ts @@ -1,6 +1,6 @@ import {writable, derived, get} from "svelte/store" import type {Writable, Readable} from "svelte/store" -import {Worker, identity, uniq, defer, sleep, assoc} from "@welshman/lib" +import {Worker, dissoc, identity, uniq, defer, sleep, assoc} from "@welshman/lib" import type {Deferred} from "@welshman/lib" import {stamp, own, hash} from "@welshman/signer" import type { @@ -164,6 +164,12 @@ export const publishThunks = (requests: ThunkRequest[]) => { return mergedThunk } +export const abortThunk = (thunk: Thunk) => { + thunk.controller.abort() + thunks.update(dissoc(thunk.event.id)) + repository.removeEvent(thunk.event.id) +} + export const thunkWorker = new Worker() thunkWorker.addGlobalHandler((thunk: Thunk) => { diff --git a/packages/lib/package.json b/packages/lib/package.json index 11ea0ad..1ea896e 100644 --- a/packages/lib/package.json +++ b/packages/lib/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/lib", - "version": "0.0.38", + "version": "0.0.39", "author": "hodlbod", "license": "MIT", "description": "A collection of utilities.", @@ -30,4 +30,4 @@ "@types/events": "^3.0.3", "events": "^3.3.0" } -} \ No newline at end of file +} diff --git a/packages/lib/src/Tools.ts b/packages/lib/src/Tools.ts index 0445994..fe051b5 100644 --- a/packages/lib/src/Tools.ts +++ b/packages/lib/src/Tools.ts @@ -622,12 +622,18 @@ export const prop = (x: Record) => x[k] as T -/** Returns a function that adds/updates property on object */ +/** Returns a function that adds/updates a property on object */ export const assoc = (k: K, v: T) => (o: U) => ({...o, [k as K]: v}) as U & Record +/** Returns a function that removes a property on object */ +export const dissoc = + (k: K) => + (o: T) => + omit([k], o) + /** Generates a hash string from input string */ export const hash = (s: string) => Math.abs(s.split("").reduce((a, b) => ((a << 5) - a + b.charCodeAt(0)) | 0, 0)).toString() diff --git a/packages/store/package.json b/packages/store/package.json index 2791084..4506986 100644 --- a/packages/store/package.json +++ b/packages/store/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/store", - "version": "0.0.15", + "version": "0.0.16", "author": "hodlbod", "license": "MIT", "description": "A collection of utilities based on svelte/store for use with welshman", diff --git a/packages/util/package.json b/packages/util/package.json index f89d42f..fac3027 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -1,6 +1,6 @@ { "name": "@welshman/util", - "version": "0.0.59", + "version": "0.0.60", "author": "hodlbod", "license": "MIT", "description": "A collection of nostr-related utilities.",