Setup system-svelte

This commit is contained in:
2023-09-17 15:02:07 +01:00
parent 1a6df18e8b
commit 4220ae5bdc
7 changed files with 193 additions and 11 deletions

View File

@ -0,0 +1,20 @@
import { type NoteStore, type RequestBuilder, type StoreSnapshot, type SystemInterface } from "@snort/system";
import { getContext } from "svelte";
export function useRequestBuilder<T extends NoteStore>(type: new () => T, rb: RequestBuilder) {
const system = getContext("snort") as SystemInterface;
type TSnap = StoreSnapshot<ReturnType<T["getSnapshotData"]>>;
return {
subscribe: (set: (value: TSnap) => void) => {
const q = system.Query(type, rb);
q.uncancel();
const release = q.feed.hook(() => {
set(q.feed.snapshot as TSnap);
});
return () => {
q.cancel();
release();
};
},
};
}