Skip to content

Commit

Permalink
Memory RxStorage: Add categorizedByWriteInput property that can be …
Browse files Browse the repository at this point in the history
…used by other plugins
  • Loading branch information
pubkey committed Apr 25, 2024
1 parent e30da3d commit 69da30e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# RxDB Changelog

<!-- CHANGELOG NEWEST -->

- Memory RxStorage: Add `categorizedByWriteInput` property that can be used by other plugins.
<!-- ADD new changes here! -->

<!-- /CHANGELOG NEWEST -->
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/storage-memory/rx-storage-instance-memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '../../rx-storage-helper.ts';
import type {
BulkWriteRow,
CategorizeBulkWriteRowsOutput,
EventBulk,
PreparedQuery,
QueryMatcher,
Expand Down Expand Up @@ -79,6 +80,14 @@ export class RxStorageInstanceMemory<RxDocType> implements RxStorageInstance<
public readonly primaryPath: StringKeys<RxDocumentData<RxDocType>>;
public closed = false;

/**
* Used by some plugins and storage wrappers
* to find out details about the internals of a write operation.
* For example if you want to know which documents really have been replaced
* or newly inserted.
*/
public categorizedByWriteInput = new WeakMap<BulkWriteRow<RxDocType>[], CategorizeBulkWriteRowsOutput<RxDocType>>();

constructor(
public readonly storage: RxStorageMemory,
public readonly databaseName: string,
Expand Down Expand Up @@ -124,6 +133,7 @@ export class RxStorageInstanceMemory<RxDocType> implements RxStorageInstance<
success.push(doc);
}

this.categorizedByWriteInput.set(documentWrites, categorized);
this.internals.ensurePersistenceTask = categorized;
if (!this.internals.ensurePersistenceIdlePromise) {
this.internals.ensurePersistenceIdlePromise = requestIdlePromiseNoQueue().then(() => {
Expand Down
1 change: 0 additions & 1 deletion src/rx-storage-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ export function observeSingle<RxDocType>(
return ret;
}


/**
* Checkpoints must be stackable over another.
* This is required form some RxStorage implementations
Expand Down

0 comments on commit 69da30e

Please sign in to comment.