Skip to main content Link Search Menu Expand Document (external link)

Differ.ts overview

Since v2.0.0


Exports Grouped by Category


constructors

chunk

Constructs a differ that knows how to diff a Chunk of values given a differ that knows how to diff the values.

Signature

declare const chunk: <Value, Patch>(
  differ: Differ<Value, Patch>
) => Differ<Chunk<Value>, Differ.Chunk.Patch<Value, Patch>>

Source

Since v2.0.0

environment

Constructs a differ that knows how to diff Env values.

Signature

declare const environment: <A>() => Differ<Context<A>, Differ.Context.Patch<A, A>>

Source

Since v2.0.0

hashMap

Constructs a differ that knows how to diff a HashMap of keys and values given a differ that knows how to diff the values.

Signature

declare const hashMap: <Key, Value, Patch>(
  differ: Differ<Value, Patch>
) => Differ<HashMap<Key, Value>, Differ.HashMap.Patch<Key, Value, Patch>>

Source

Since v2.0.0

hashSet

Constructs a differ that knows how to diff a HashSet of values.

Signature

declare const hashSet: <Value>() => Differ<HashSet<Value>, Differ.HashSet.Patch<Value>>

Source

Since v2.0.0

make

Constructs a new Differ.

Signature

declare const make: <Value, Patch>(params: {
  readonly empty: Patch
  readonly diff: (oldValue: Value, newValue: Value) => Patch
  readonly combine: (first: Patch, second: Patch) => Patch
  readonly patch: (patch: Patch, oldValue: Value) => Value
}) => Differ<Value, Patch>

Source

Since v2.0.0

readonlyArray

Constructs a differ that knows how to diff a ReadonlyArray of values.

Signature

declare const readonlyArray: <Value, Patch>(
  differ: Differ<Value, Patch>
) => Differ<ReadonlyArray<Value>, Differ.ReadonlyArray.Patch<Value, Patch>>

Source

Since v2.0.0

models

Differ (interface)

A Differ<Value, Patch> knows how to compare an old value and new value of type Value to produce a patch of type Patch that describes the differences between those values. A Differ also knows how to apply a patch to an old value to produce a new value that represents the old value updated with the changes described by the patch.

A Differ can be used to construct a FiberRef supporting compositional updates using the FiberRef.makePatch constructor.

The Differ companion object contains constructors for Differ values for common data types such as Chunk, HashMap, and HashSet. In addition, Differvalues can be transformed using the transformoperator and combined using theorElseEitherandzipoperators. This allows creatingDiffer` values for arbitrarily complex data types compositionally.

Signature

export interface Differ<in out Value, in out Patch> extends Pipeable {
  readonly [TypeId]: {
    readonly _V: Types.Invariant<Value>
    readonly _P: Types.Invariant<Patch>
  }
  readonly empty: Patch
  diff(oldValue: Value, newValue: Value): Patch
  combine(first: Patch, second: Patch): Patch
  patch(patch: Patch, oldValue: Value): Value
}

Source

Since v2.0.0

patch

combine

Combines two patches to produce a new patch that describes the updates of the first patch and then the updates of the second patch. The combine operation should be associative. In addition, if the combine operation is commutative then joining multiple fibers concurrently will result in deterministic FiberRef values.

Signature

declare const combine: {
  <Patch>(first: Patch, second: Patch): <Value>(self: Differ<Value, Patch>) => Patch
  <Value, Patch>(self: Differ<Value, Patch>, first: Patch, second: Patch): Patch
}

Source

Since v2.0.0

diff

Signature

declare const diff: {
  <Value>(oldValue: Value, newValue: Value): <Patch>(self: Differ<Value, Patch>) => Patch
  <Value, Patch>(self: Differ<Value, Patch>, oldValue: Value, newValue: Value): Patch
}

Source

Since v2.0.0

empty

An empty patch that describes no changes.

Signature

declare const empty: <Value, Patch>(self: Differ<Value, Patch>) => Patch

Source

Since v2.0.0

patch

Applies a patch to an old value to produce a new value that is equal to the old value with the updates described by the patch.

Signature

declare const patch: {
  <Patch, Value>(patch: Patch, oldValue: Value): (self: Differ<Value, Patch>) => Value
  <Patch, Value>(self: Differ<Value, Patch>, patch: Patch, oldValue: Value): Value
}

Source

Since v2.0.0

symbol

TypeId

Signature

declare const TypeId: unique symbol

Source

Since v2.0.0

TypeId (type alias)

Signature

type TypeId = typeof TypeId

Source

Since v2.0.0

utils

Differ (namespace)

Source

Since v2.0.0

Context (namespace)

Source

Since v2.0.0

Patch (interface)

A Patch<Input, Output> describes an update that transforms a Env<Input> to a Env<Output> as a data structure. This allows combining updates to different services in the environment in a compositional way.

Signature

export interface Patch<in Input, out Output> extends Equal {
  readonly [ContextPatchTypeId]: {
    readonly _Input: Types.Contravariant<Input>
    readonly _Output: Types.Covariant<Output>
  }
}

Source

Since v2.0.0

TypeId (type alias)

Signature

type TypeId = typeof ContextPatchTypeId

Source

Since v2.0.0

Chunk (namespace)

Source

Since v2.0.0

Patch (interface)

A patch which describes updates to a chunk of values.

Signature

export interface Patch<in out Value, in out Patch> extends Equal {
  readonly [ChunkPatchTypeId]: {
    readonly _Value: Types.Invariant<Value>
    readonly _Patch: Types.Invariant<Patch>
  }
}

Source

Since v2.0.0

TypeId (type alias)

Signature

type TypeId = typeof ChunkPatchTypeId

Source

Since v2.0.0

HashMap (namespace)

Source

Since v2.0.0

Patch (interface)

A patch which describes updates to a map of keys and values.

Signature

export interface Patch<in out Key, in out Value, in out Patch> extends Equal {
  readonly [HashMapPatchTypeId]: {
    readonly _Key: Types.Invariant<Key>
    readonly _Value: Types.Invariant<Value>
    readonly _Patch: Types.Invariant<Patch>
  }
}

Source

Since v2.0.0

TypeId (type alias)

Signature

type TypeId = typeof HashMapPatchTypeId

Source

Since v2.0.0

HashSet (namespace)

Source

Since v2.0.0

Patch (interface)

A patch which describes updates to a set of values.

Signature

export interface Patch<in out Value> extends Equal {
  readonly [HashSetPatchTypeId]: {
    readonly _Value: Types.Invariant<Value>
  }
}

Source

Since v2.0.0

TypeId (type alias)

Signature

type TypeId = typeof HashSetPatchTypeId

Source

Since v2.0.0

Or (namespace)

Source

Since v2.0.0

Patch (interface)

A patch which describes updates to either one value or another.

Signature

export interface Patch<in out Value, in out Value2, in out Patch, in out Patch2> extends Equal {
  readonly [OrPatchTypeId]: {
    readonly _Value: Types.Invariant<Value>
    readonly _Value2: Types.Invariant<Value2>
    readonly _Patch: Types.Invariant<Patch>
    readonly _Patch2: Types.Invariant<Patch2>
  }
}

Source

Since v2.0.0

TypeId (type alias)

Signature

type TypeId = typeof OrPatchTypeId

Source

Since v2.0.0

ReadonlyArray (namespace)

Source

Since v2.0.0

Patch (interface)

A patch which describes updates to a ReadonlyArray of values.

Signature

export interface Patch<in out Value, in out Patch> extends Equal {
  readonly [ReadonlyArrayPatchTypeId]: {
    readonly _Value: Types.Invariant<Value>
    readonly _Patch: Types.Invariant<Patch>
  }
}

Source

Since v2.0.0

TypeId (type alias)

Signature

type TypeId = typeof ReadonlyArrayPatchTypeId

Source

Since v2.0.0

orElseEither

Combines this differ and the specified differ to produce a differ that knows how to diff the sum of their values.

Signature

declare const orElseEither: {
  <Value2, Patch2>(
    that: Differ<Value2, Patch2>
  ): <Value, Patch>(
    self: Differ<Value, Patch>
  ) => Differ<Either<Value2, Value>, Differ.Or.Patch<Value, Value2, Patch, Patch2>>
  <Value, Patch, Value2, Patch2>(
    self: Differ<Value, Patch>,
    that: Differ<Value2, Patch2>
  ): Differ<Either<Value2, Value>, Differ.Or.Patch<Value, Value2, Patch, Patch2>>
}

Source

Since v2.0.0

transform

Transforms the type of values that this differ knows how to differ using the specified functions that map the new and old value types to each other.

Signature

declare const transform: {
  <Value, Value2>(options: {
    readonly toNew: (value: Value) => Value2
    readonly toOld: (value: Value2) => Value
  }): <Patch>(self: Differ<Value, Patch>) => Differ<Value2, Patch>
  <Value, Patch, Value2>(
    self: Differ<Value, Patch>,
    options: { readonly toNew: (value: Value) => Value2; readonly toOld: (value: Value2) => Value }
  ): Differ<Value2, Patch>
}

Source

Since v2.0.0

update

Constructs a differ that just diffs two values by returning a function that sets the value to the new value. This differ does not support combining multiple updates to the value compositionally and should only be used when there is no compositional way to update them.

Signature

declare const update: <A>() => Differ<A, (a: A) => A>

Source

Since v2.0.0

updateWith

A variant of update that allows specifying the function that will be used to combine old values with new values.

Signature

declare const updateWith: <A>(f: (x: A, y: A) => A) => Differ<A, (a: A) => A>

Source

Since v2.0.0

zip

Combines this differ and the specified differ to produce a new differ that knows how to diff the product of their values.

Signature

declare const zip: {
  <Value2, Patch2>(
    that: Differ<Value2, Patch2>
  ): <Value, Patch>(self: Differ<Value, Patch>) => Differ<readonly [Value, Value2], readonly [Patch, Patch2]>
  <Value, Patch, Value2, Patch2>(
    self: Differ<Value, Patch>,
    that: Differ<Value2, Patch2>
  ): Differ<readonly [Value, Value2], readonly [Patch, Patch2]>
}

Source

Since v2.0.0