Skip to content

Commit 7e80360

Browse files
fix(directory): Add clearInternal event and mark it as internal (#25927)
The standard clear event has the below limitation. It does not tell you which subdirectory was cleared. - It's emitted on the root SharedDirectory for all clear operations - But it does NOT include the path of which directory was cleared The event only provides: - local: Whether it was a local or remote operation - target: SharedDirectory itself This limitation came to notice while adding event testing for directory: #25477. The oracle needs to track the state of every directory in the tree (root and all subdirectories). When a clear operation happens: - Without path information: The oracle would have to clear ALL directories in its model, even though only one specific directory was cleared - Can't distinguish: A clear on /subdir1 vs /subdir2 vs root (/) would all look the same This change adds a new event `clearInternal` which takes in the absolute path and it is marked as internal. [AB#54326](https://dev.azure.com/fluidframework/internal/_workitems/edit/54326)
1 parent 335ed1a commit 7e80360

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

packages/dds/map/src/directory.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import type {
4040
IDirectoryEvents,
4141
IDirectoryValueChanged,
4242
ISharedDirectory,
43-
ISharedDirectoryEvents,
43+
ISharedDirectoryEventsInternal,
4444
IValueChanged,
4545
} from "./interfaces.js";
4646
import type {
@@ -402,7 +402,7 @@ interface SequenceData {
402402
* @sealed
403403
*/
404404
export class SharedDirectory
405-
extends SharedObject<ISharedDirectoryEvents>
405+
extends SharedObject<ISharedDirectoryEventsInternal>
406406
implements ISharedDirectory
407407
{
408408
/**
@@ -1570,6 +1570,7 @@ class SubDirectory extends TypedEventEmitter<IDirectoryEvents> implements IDirec
15701570
if (!this.directory.isAttached()) {
15711571
this.sequencedStorageData.clear();
15721572
this.directory.emit("clear", true, this.directory);
1573+
this.directory.emit("clearInternal", this.absolutePath, true, this.directory);
15731574
return;
15741575
}
15751576

@@ -1581,6 +1582,7 @@ class SubDirectory extends TypedEventEmitter<IDirectoryEvents> implements IDirec
15811582
this.pendingStorageData.push(pendingClear);
15821583

15831584
this.directory.emit("clear", true, this.directory);
1585+
this.directory.emit("clearInternal", this.absolutePath, true, this.directory);
15841586
const op: IDirectoryOperation = {
15851587
type: "clear",
15861588
path: this.absolutePath,
@@ -1907,6 +1909,7 @@ class SubDirectory extends TypedEventEmitter<IDirectoryEvents> implements IDirec
19071909
// is no optimistically-applied local pending clear that would supersede this remote clear.
19081910
if (!this.pendingStorageData.some((entry) => entry.type === "clear")) {
19091911
this.directory.emit("clear", local, this.directory);
1912+
this.directory.emit("clearInternal", this.absolutePath, local, this.directory);
19101913
}
19111914

19121915
// For pending set operations, emit valueChanged events

packages/dds/map/src/interfaces.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,28 @@ export interface IDirectoryEvents extends IEvent {
277277
(event: "undisposed", listener: (target: IEventThisPlaceHolder) => void);
278278
}
279279

280+
/**
281+
* Internal events for {@link ISharedDirectory}.
282+
* @internal
283+
*/
284+
export interface ISharedDirectoryEventsInternal extends ISharedDirectoryEvents {
285+
/**
286+
* Emitted when the {@link ISharedDirectory} is cleared.
287+
*
288+
* @remarks Listener parameters:
289+
*
290+
* - `path` - The absolute path to the directory that was cleared.
291+
*
292+
* - `local` - Whether the clear originated from this client.
293+
*
294+
* - `target` - The {@link ISharedDirectory} itself.
295+
*/
296+
(
297+
event: "clearInternal",
298+
listener: (path: string, local: boolean, target: IEventThisPlaceHolder) => void,
299+
);
300+
}
301+
280302
/**
281303
* Provides a hierarchical organization of map-like data structures as SubDirectories.
282304
* The values stored within can be accessed like a map, and the hierarchy can be navigated using path syntax.

0 commit comments

Comments
 (0)