Skip to main content

NodeProvider TypeAlias

A provider for values in tree nodes.

This API is provided as an alpha preview and may change without notice.

To use, import via fluid-framework/alpha.

For more information about our API support guarantees, see here.

Sealed

This type is "sealed," meaning that code outside of the library defining it should not implement or extend it. Future versions of this type may add members or make typing of readonly members more specific.

Signature

/** @sealed */
export type NodeProvider<T> = T | (() => T);

Type Parameters

ParameterDescription
T

Remarks

This type represents two ways to provide node values:

  1. **A value**: Provide any value directly (number, string, object, array, etc.). When a value is provided, the data is copied for each use to ensure independence between instances. The value must be of an allowed type for the field.
  1. **A generator function**: A function that returns a value. The function is called each time a default is needed, allowing for dynamic defaults or explicit control over value creation. The return value must be of an allowed type for the field.

Values should be preferred over generator functions when possible, as they are simpler and more efficient. Generator functions should be used when the default value needs to be dynamic or when it is not possible to provide a value directly.

Example

// Provide a value directly
factory.withDefault(factory.required(factory.string), "default")
factory.withDefault(factory.optional(Person), new Person({ name: "Guest" }))

// Use a generator function
factory.withDefault(factory.required(factory.string), () => crypto.randomUUID())
factory.withDefault(factory.optional(Person), () => new Person({ name: "Guest" }))