Getting Started
There are four main components that makeup the applesauce libraries: Helpers, the EventStore, the QueryStore, and Queries
Helpers
Helper methods are the core of the library and serve to extract and parse nostr events
A few good example methods are getProfileContent which returns the parsed content of a kind:0 event and getOutboxes which returns an array of outbox (write) relays from a kind:10002 relay list event
EventStore
The EventStore class is an in-memory database that can be used to subscribe to events and timeline updates
The event store does not make any relay connections or fetch any data, nor does it persist the events. its sole purpose is to store events and notify the UI when there are new events
NOTE
Its recommended that you only create a single instance of the EventStore
for your app
QueryStore
The QueryStore
is built on top of the EventStore
and handles managing and running the queries. its primary role is to ensure that only a single query for each filter is created and that it is wrapped in the rxjs share operator for performance reasons
IMPORTANT
For performance reasons UI components should only subscribe to the QueryStore
and NOT the EventStore
Queries
Queries are more complex subscriptions that can be run against the QueryStore
For example the ProfileQuery query can be used to subscribe to changes to a users profile
const sub = queryStore
.createQuery(ProfileQuery, "3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d")
.subscribe((profile) => {
if (profile) console.log(profile);
});
Or the MailboxesQuery can be used to subscribe to changes to a users outbox and inbox relays
const sub = queryStore
.createQuery(MailboxesQuery, "3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d")
.subscribe((mailboxes) => {
if (mailboxes) {
console.log(mailboxes.inboxes, mailboxes.outboxes);
}
});