Reactive
AppleSauce is built using RxJS observables, which makes subscribing to events simple and reactive and avoids messy state management.
Build reactive nostr UI with less code
AppleSauce is built on top of RxJS and uses the observable pattern to provide a reactive, event-driven architecture for Nostr applications.
The event store makes it easy to query and subscribe to events reactively:
import { EventStore } from "applesauce-core/event-store";
// Create an event store
const store = new EventStore();
// Subscribe to a timeline of kind:1 events (notes)
store.timeline({ kinds: [1], limit: 10 }).subscribe((events) => {
console.log(`Timeline updated: ${events.length} notes`);
renderTimeline(events);
});
// Add events to the store - timeline updates automatically
store.add(event);Connect to relays and fetch events with minimal code:
import { RelayPool, onlyEvents } from "applesauce-relay";
// Create an event store to hold state (events)
const store = new EventStore();
// Create a relay connection
const pool = new RelayPool();
// Subscribe to events from the relay
pool
.subscription(["wss://relay.damus.io", "wss://nos.lol", "wss://relay.nostr.band"], { kinds: [1], limit: 20 })
.pipe(onlyEvents())
.subscribe((event) => store.add(event));
// Subscribe to the timeline from the event store
store.timeline({ kinds: [1] }).subscribe((events) => {
console.log(`Timeline updated: ${events.length} notes`);
});