Skip to content

Commit

Permalink
docs(json-crdt): ✏️ improve nodes automated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Oct 29, 2023
1 parent b9ad870 commit 325a969
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/json-crdt/model/api/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,28 @@ export class NodeApi<N extends JsonNode = JsonNode> implements Printable {

/** @ignore */
private ev: undefined | NodeEvents = undefined;

/**
* Event target for listening to node changes. You can subscribe to `"view"`
* events, which are triggered every time the node's view changes.
*
* ```typescript
* node.events.on('view', () => {
* // do something...
* });
* ```
*/
public get events(): NodeEvents {
const et = this.ev;
return et || (this.ev = new NodeEvents(this));
}

/**
* Find a child node at the given path starting from this node.
*
* @param path Path to the child node to find.
* @returns JSON CRDT node at the given path.
*/
public find(path?: ApiPath): JsonNode {
const node = this.node;
if (path === undefined) {
Expand All @@ -48,6 +65,13 @@ export class NodeApi<N extends JsonNode = JsonNode> implements Printable {
return find(this.node, path);
}

/**
* Find a child node at the given path starting from this node and wrap it in
* a local changes API.
*
* @param path Path to the child node to find.
* @returns Local changes API for the child node at the given path.
*/
public in(path?: ApiPath) {
const node = this.find(path);
return this.api.wrap(node as any);
Expand Down

0 comments on commit 325a969

Please sign in to comment.