refactor: reactions grouping and other fixes
This commit is contained in:
@ -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();
|
||||
})();
|
||||
```
|
||||
|
Reference in New Issue
Block a user