TreeNode Class
A non-leaf SharedTree node. Includes objects, arrays, and maps.
Signature
/** @sealed */
export declare abstract class TreeNode implements WithType
Implements: WithType
Remarks
Base type which all nodes extend.
This type can be used as a type to indicate/document values which should be tree nodes. Runtime use of this class object (for example when used with instanceof
or extending it), is not currently supported.
There are three ways to get instances of TreeNode:
- From a TreeView loading nodes from an existing document, or creating local copies of nodes inserted by a remote collaborator. This case provides an InternalTreeNode to the constructor: subclasses must not modify how the constructor handles this case. 2. Explicit construction of Unhydrated nodes using either TreeNodeSchemaClass as a constructor or TreeNodeSchemaNonClass.create. Either way the TreeNodeSchema produced must be produced using a SchemaFactory. 3. Implicit construction: Several APIs which logically require an unhydrated TreeNode also allow passing in a value which could be used to explicitly construct the node instead. These APIs internally call the constructor with the provided value, so it's really just a special case of the above option. Note that when constructing nodes, sometimes implicit construction is not allowed (either at runtime due to ambiguous types or at compile time due to TypeScript limitations): in such cases, explicit construction must be used.
Constructors
Constructor | Description |
---|---|
(constructor)(token) | TreeNodes must extend schema classes created by SchemaFactory, and therefore this constructor should not be invoked directly by code outside this package. |
Static Methods
Method | Return Type | Description |
---|---|---|
[Symbol.hasInstance](value) | value is TreeNode | Provides instanceof support for testing if a value is a TreeNode . |
[Symbol.hasInstance](this, value) | value is InstanceType<TSchema> | Provides instanceof support for all schema classes with public constructors. |
Properties
Property | Alerts | Modifiers | Type | Description |
---|---|---|---|---|
[typeNameSymbol] | Deprecated |
readonly |
string | Adds a type symbol for stronger typing. |
[typeSchemaSymbol] | readonly |
TreeNodeSchemaClass | Adds a type symbol for stronger typing. |
Constructor Details
(constructor)
TreeNodes must extend schema classes created by SchemaFactory, and therefore this constructor should not be invoked directly by code outside this package.
Signature
protected constructor(token: unknown);
Parameters
Parameter | Type | Description |
---|---|---|
token | unknown |
Property Details
[typeNameSymbol]
Adds a type symbol for stronger typing.
Use typeSchemaSymbol instead.
Signature
abstract get [typeNameSymbol](): string;
Type: string
[typeSchemaSymbol]
Adds a type symbol for stronger typing.
Signature
abstract get [typeSchemaSymbol](): TreeNodeSchemaClass;
Type: TreeNodeSchemaClass
Method Details
[Symbol.hasInstance]
Provides instanceof
support for testing if a value is a TreeNode
.
Signature
static [Symbol.hasInstance](value: unknown): value is TreeNode;
Remarks
For more options, like including leaf values or narrowing to collections of schema, use is
or schema
from TreeNodeApi.
Parameters
Parameter | Type | Description |
---|---|---|
value | unknown |
Returns
Return type: value is TreeNode
[Symbol.hasInstance]
Provides instanceof
support for all schema classes with public constructors.
Signature
static [Symbol.hasInstance]<TSchema extends abstract new (...args: any[]) => TreeNode>(this: TSchema, value: unknown): value is InstanceType<TSchema>;
Type Parameters
Parameter | Constraint | Description |
---|---|---|
TSchema | abstract new (...args: any[]) => TreeNode |
Remarks
For more options, like including leaf values or narrowing to collections of schema, use is
or schema
from TreeNodeApi.
Parameters
Parameter | Type | Description |
---|---|---|
this | TSchema | |
value | unknown |
Returns
Return type: value is InstanceType<TSchema>