/
parent.ts
67 lines (63 loc) · 2.15 KB
/
parent.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { Collab } from "./collab";
import { CollabID } from "./collab_id";
import { IRuntime } from "./iruntime";
import { MetaRequest } from "./updates";
/**
* Interface implemented by something that can be a parent
* of a [[Collab]].
*
* Only reference this interface directly if you
* are a [[Collab]] implementing it in order to be a [[Parent]].
* Otherwise, use the [[Parent]] type.
*
* See [[CObject]]'s implementation for "default" behavior.
*/
export interface IParent {
/**
* Internal ([[Collab.send]]) use only.
*
* Sends the given message on behalf of child.
* In general, this parent is then responsible for delivering the given
* message to [[Collab.receive]] on each replica of child, with
* guarantees set by the [[runtime]].
*
* @param child The caller.
* @param messageStack As in [[Collab.send]].
* @param metaRequests As in [[Collab.send]].
*/
childSend(
child: Collab,
messageStack: (Uint8Array | string)[],
metaRequests: MetaRequest[]
): void;
/**
* Returns a [[CollabID]] for the given *strict* descendant of this
* parent.
*
* The CollabID may be passed to [[fromID]] on any replica of this
* parent (but not other parents) to obtain that replica's copy of
* `descendant`.
*
* @param descendant A strict (non-`this`) descendant of this parent.
*/
idOf<C extends Collab>(descendant: C): CollabID<C>;
/**
* Inverse of [[idOf]].
*
* Specifically, given a [[CollabID]] returned by [[idOf]] on some replica of
* this parent, returns this replica's copy of the original
* `descendant`. If that descendant does not exist (e.g., it was deleted
* or it is not present in this program version), returns undefined.
*
* @param id A CollabID from [[idOf]].
* @param startIndex Internal (parent) use only.
* If provided, treat `id.collabIDPath` as if
* it starts at startIndex instead of 0.
*/
fromID<C extends Collab>(id: CollabID<C>, startIndex?: number): C | undefined;
}
/**
* Something that can be a parent of a [[Collab]]: either
* an [[IRuntime]] or a [[Collab]] that can have children.
*/
export type Parent = IParent & (Collab | IRuntime);