@nostr-dev-kit/ndk-svelte
Version:
This package provides convenience functionalities to make usage of NDK with Svelte nicer.
27 lines (24 loc) • 931 B
TypeScript
import NDK, { NDKEvent, NDKFilter, NDKSubscriptionOptions, NDKRelaySet, NDKRelay } from '@nostr-dev-kit/ndk';
type ClassWithConvertFunction<T extends NDKEvent> = {
from: (event: NDKEvent) => T | undefined;
};
type NDKSubscribeOptions = NDKSubscriptionOptions & {
autoStart?: boolean;
repostsFilters?: NDKFilter[];
unrefUnsubscribeTimeout?: number;
relaySet?: NDKRelaySet;
skipDeleted?: boolean;
onEose?: () => void;
onEvent?: (event: NDKEvent, relay?: NDKRelay) => void;
};
type Actions = {
unsubscribe?: () => void;
};
declare class NDKSvelte extends NDK {
/**
* Subscribes to NDK events and returns a reactive list of events.
* Automatically cleans up the subscription when no longer needed.
*/
$subscribe: <T extends NDKEvent>(filters: NDKFilter[], opts?: NDKSubscribeOptions, klass?: ClassWithConvertFunction<T>) => T[] & Actions;
}
export { NDKSvelte as default };