refactor: consolidate SDK Watchable with generic map/eq and rename call to fetch

This commit is contained in:
Aiden McClelland
2026-03-11 15:13:40 -06:00
parent c59c619e12
commit a782cb270b
16 changed files with 263 additions and 897 deletions

View File

@@ -1,18 +1,47 @@
import { Effects } from '../Effects'
import { Manifest, PackageId } from '../osBindings'
import { deepEqual } from './deepEqual'
import { Watchable } from './Watchable'
export class GetServiceManifest extends Watchable<Manifest> {
export class GetServiceManifest<
Mapped = Manifest | null,
> extends Watchable<Manifest | null, Mapped> {
protected readonly label = 'GetServiceManifest'
constructor(
effects: Effects,
readonly opts: { packageId: PackageId },
options?: {
map?: (value: Manifest | null) => Mapped
eq?: (a: Mapped, b: Mapped) => boolean
},
) {
super(effects)
super(effects, options)
}
protected call(callback?: () => void) {
protected fetch(callback?: () => void) {
return this.effects.getServiceManifest({ ...this.opts, callback })
}
}
export function getServiceManifest(
effects: Effects,
packageId: PackageId,
): GetServiceManifest<Manifest | null>
export function getServiceManifest<Mapped>(
effects: Effects,
packageId: PackageId,
map: (manifest: Manifest | null) => Mapped,
eq?: (a: Mapped, b: Mapped) => boolean,
): GetServiceManifest<Mapped>
export function getServiceManifest<Mapped>(
effects: Effects,
packageId: PackageId,
map?: (manifest: Manifest | null) => Mapped,
eq?: (a: Mapped, b: Mapped) => boolean,
): GetServiceManifest<Mapped> {
return new GetServiceManifest<Mapped>(effects, { packageId }, {
map: map ?? ((a) => a as Mapped),
eq: eq ?? ((a, b) => deepEqual(a, b)),
})
}