Add some type utils, findFeed, and fix feed listener to use limit: 0 instead of since

This commit is contained in:
Jon Staab
2025-09-09 16:12:16 -07:00
parent 9a476d2c30
commit 599e6a5085
19 changed files with 95 additions and 16 deletions
+12
View File
@@ -30,6 +30,12 @@ export class FeedController {
// Load events with specified limit
load(limit: number): Promise<void>
// Get listener function (memoized)
getListener(): Promise<() => Promise<void>>
// Listen for new events in the feed
listen(): Promise<void>
}
```
@@ -90,4 +96,10 @@ await controller.load(50)
// Load more events
await controller.load(50)
// Listen for new events
const unlisten = controller.listen()
// Unsubscribe from listener
unlisten()
```
+17
View File
@@ -123,6 +123,23 @@ walkFeed(feed, (node) => {
})
```
Find a specific feed in a feed tree:
```typescript
const feed = makeIntersectionFeed(
makeAuthorFeed("pubkey1"),
makeUnionFeed(
makeKindFeed(1),
makeTagFeed("#t", "bitcoin")
)
)
// Find a feed matching a specific condition
const bitcoinTagFeed = findFeed(feed, (f) =>
isTagFeed(f) && getFeedArgs(f)[1] === "bitcoin"
)
```
## Feed Simplification
Flatten nested feeds of the same type:
+30
View File
@@ -2,6 +2,36 @@
The `Tools` module provides a comprehensive collection of utility functions for common programming tasks. It includes functions for array manipulation, object handling, type checking, math operations, and more.
## Working with types
Utility types for TypeScript development:
```typescript
// Override properties of type T with properties from type R
export type Override<T, R> = Omit<T, keyof R> & R;
// Make specific properties of type T optional
export type MakeOptional<T, K extends keyof T> = Override<T, Partial<Pick<T, K>>>;
```
Examples:
```typescript
interface User {
id: string;
name: string;
email: string;
age: number;
}
// Override the id to be a number instead
type UserWithNumericId = Override<User, { id: number }>;
// Result: { id: number; name: string; email: string; age: number; }
// Make email and age optional
type PartialUser = MakeOptional<User, 'email' | 'age'>;
// Result: { id: string; name: string; email?: string; age?: number; }
```
## Basic functional programming utilities
```typescript