Skip to content

Commit

Permalink
feat: add modifications to publish event
Browse files Browse the repository at this point in the history
  • Loading branch information
icidasset committed Dec 21, 2023
1 parent d8ec1b5 commit d6b654c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
22 changes: 14 additions & 8 deletions packages/nest/src/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ export interface FileSystemOptions {
/** @group 🪺 :: START HERE */
export class FileSystem {
readonly #blockstore: Blockstore
readonly #debouncedDataRootUpdate: (...dataRoots: CID[]) => Promise<void>
readonly #debouncedDataRootUpdate: (
...args: Array<{ dataRoot: CID; modifications: Modification[] }>
) => Promise<void>

readonly #eventEmitter: Emittery<Events>
readonly #onCommit: CommitVerifier
readonly #rng: Rng.Rng
Expand All @@ -86,10 +89,13 @@ export class FileSystem {
this.#rootTree = rootTree

this.#debouncedDataRootUpdate = debounce(
async (...dataRoots: CID[]): Promise<void> => {
const dataRoot = dataRoots.at(-1)
async (
...args: Array<{ dataRoot: CID; modifications: Modification[] }>
): Promise<void> => {
const modifications = args.flatMap((a) => a.modifications)
const dataRoot = args.at(-1)?.dataRoot
if (dataRoot !== undefined) {
await this.#eventEmitter.emit('publish', { dataRoot })
await this.#eventEmitter.emit('publish', { dataRoot, modifications })
}
},
settleTimeBeforePublish
Expand Down Expand Up @@ -664,13 +670,13 @@ export class FileSystem {
mutationOptions.skipPublish === false ||
mutationOptions.skipPublish === undefined
) {
await this.#publish(dataRoot)
await this.#publish(dataRoot, modifications)
}

// Fin
return {
modifications,
dataRoot,
modifications,
}
}

Expand Down Expand Up @@ -796,8 +802,8 @@ export class FileSystem {

// ㊙️ ▒▒ PUBLISHING

async #publish(dataRoot: CID): Promise<void> {
async #publish(dataRoot: CID, modifications: Modification[]): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.#debouncedDataRootUpdate(dataRoot)
this.#debouncedDataRootUpdate({ dataRoot, modifications })
}
}
5 changes: 4 additions & 1 deletion packages/nest/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export type Events = {
dataRoot: CID
modifications: Modification[]
}
publish: { dataRoot: CID }
publish: {
dataRoot: CID
modifications: Modification[]
}
}

export type Listener<
Expand Down

0 comments on commit d6b654c

Please sign in to comment.