Interface ModelOptions<TProps, FS, TS>

Model options.

interface ModelOptions<TProps, FS, TS> {
    fromSnapshotProcessor?: ((sn: FS) => Flatten<{
        [k in string | number | symbol]?: IsNeverType<TProps[k]["$fromSnapshotOverride"], SnapshotInOf<(...)[(...)]["$creationValueType"]>, TProps[k]["$fromSnapshotOverride"]> extends R
            ? R
            : never
    } & {
        [k in any]: IsNeverType<TProps[k]["$fromSnapshotOverride"], SnapshotInOf<TProps[k]["$creationValueType"]>, TProps[k]["$fromSnapshotOverride"]> extends R
            ? R
            : never
    }>);
    toSnapshotProcessor?: ((sn: Flatten<{
        [k in string | number | symbol]: IsNeverType<TProps[k]["$toSnapshotOverride"], SnapshotOutOf<TProps[k]["$valueType"]>, TProps[k]["$toSnapshotOverride"]> extends R
            ? R
            : never
    }>, modelInstance: any) => TS);
    valueType?: boolean;
}

Type Parameters

Properties

fromSnapshotProcessor?: ((sn: FS) => Flatten<{
    [k in string | number | symbol]?: IsNeverType<TProps[k]["$fromSnapshotOverride"], SnapshotInOf<(...)[(...)]["$creationValueType"]>, TProps[k]["$fromSnapshotOverride"]> extends R
        ? R
        : never
} & {
    [k in any]: IsNeverType<TProps[k]["$fromSnapshotOverride"], SnapshotInOf<TProps[k]["$creationValueType"]>, TProps[k]["$fromSnapshotOverride"]> extends R
        ? R
        : never
}>)

Optional transformation that will be run when converting from a snapshot to the data part of the model. Useful for example to do versioning and keep the data part up to date with the latest version of the model.

Type declaration

    • (sn): Flatten<{
          [k in string | number | symbol]?: IsNeverType<TProps[k]["$fromSnapshotOverride"], SnapshotInOf<(...)[(...)]["$creationValueType"]>, TProps[k]["$fromSnapshotOverride"]> extends R
              ? R
              : never
      } & {
          [k in any]: IsNeverType<TProps[k]["$fromSnapshotOverride"], SnapshotInOf<TProps[k]["$creationValueType"]>, TProps[k]["$fromSnapshotOverride"]> extends R
              ? R
              : never
      }>
    • Parameters

      • sn: FS

        The custom input snapshot.

      Returns Flatten<{
          [k in string | number | symbol]?: IsNeverType<TProps[k]["$fromSnapshotOverride"], SnapshotInOf<(...)[(...)]["$creationValueType"]>, TProps[k]["$fromSnapshotOverride"]> extends R
              ? R
              : never
      } & {
          [k in any]: IsNeverType<TProps[k]["$fromSnapshotOverride"], SnapshotInOf<TProps[k]["$creationValueType"]>, TProps[k]["$fromSnapshotOverride"]> extends R
              ? R
              : never
      }>

      An input snapshot that must match the expected model input snapshot.

toSnapshotProcessor?: ((sn: Flatten<{
    [k in string | number | symbol]: IsNeverType<TProps[k]["$toSnapshotOverride"], SnapshotOutOf<TProps[k]["$valueType"]>, TProps[k]["$toSnapshotOverride"]> extends R
        ? R
        : never
}>, modelInstance: any) => TS)

Optional transformation that will be run when converting the data part of the model into a snapshot.

Type declaration

    • (sn, modelInstance): TS
    • Parameters

      • sn: Flatten<{
            [k in string | number | symbol]: IsNeverType<TProps[k]["$toSnapshotOverride"], SnapshotOutOf<TProps[k]["$valueType"]>, TProps[k]["$toSnapshotOverride"]> extends R
                ? R
                : never
        }>

        The output snapshot.

      • modelInstance: any

        The model instance.

      Returns TS

      a custom output snapshot.

valueType?: boolean

A value type will be cloned automatically when being attached to a new tree. The default is false.