refactor: reactions grouping and other fixes

This commit is contained in:
2024-01-09 16:40:31 +00:00
parent 4455651d47
commit 80fa5a132b
58 changed files with 344 additions and 501 deletions

View File

@ -5,12 +5,7 @@ A collection of caching and querying techniquies used by https://snort.social to
Simple example:
```js
import {
NostrSystem,
RequestBuilder,
StoreSnapshot,
NoteCollection
} from "@snort/system"
import { NostrSystem, RequestBuilder, StoreSnapshot, NoteCollection } from "@snort/system";
// Singleton instance to store all connections and access query fetching system
const System = new NostrSystem({});
@ -30,25 +25,11 @@ const System = new NostrSystem({});
.kinds([1])
.limit(10);
const q = System.Query(NoteCollection, rb);
const q = System.Query(rb);
// basic usage using "onEvent", fired every 100ms
q.feed.onEvent(evs => {
q.on("event", evs => {
console.log(evs);
// something else..
});
// Hookable type using change notification, limited to every 500ms
const release = q.feed.hook(() => {
// since we use the NoteCollection we expect NostrEvent[]
// other stores provide different data, like a single event instead of an array (latest version)
const state = q.feed.snapshot as StoreSnapshot<ReturnType<NoteCollection["getSnapshotData"]>>;
// do something with snapshot of store
console.log(`We have ${state.data?.length} events now!`);
});
// release the hook when its not needed anymore
// these patterns will be managed in @snort/system-react to make it easier to use react or other UI frameworks
release();
})();
```