Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Cursor<T>

A cursor provides read/write access to a path location within a nested (Atom-like) parent state.

remarks

Cursors behave like Atoms for all practical purposes, i.e. support {@link @thi.ng/api#IDeref.deref}, IReset.reset, ISwap.swap, {@link @thi.ng/api#IWatch.addWatch} etc. However, when updating a cursor's value, the parent state will be updated at the cursor's path as well (incl. triggering any watches and/or validators) attached to the parent. Likewise, when the parent state is modified externally, the cursor's value will automatically update as well. The update order of cursor's sharing a common parent is undefined, but can be overridden by extending this class with a custom {@link @thi.ng/api#IWatch.notifyWatches} implementation.

If creating multiple cursors w/ a shared parent and each cursor configured with a custom ID (provided via config object to ctor), it's the user's responsibility to ensure the given IDs are unique. Cursors are implemented by attaching a watch to the parent and the ID is used to identify each watch.

When using the optional validator predicate (also specified via config object to ctor), the cursor's validator MUST NOT conflict with the one assigned to the parent or else both will go out-of-sync. Therefore, when requiring validation and updating values via cursors it's recommended to only specify validators for leaf-level cursors in the hierarchy.

Type parameters

  • T

Hierarchy

  • Cursor

Implements

  • IAtom<T>
  • IID<string>
  • IRelease

Index

Constructors

constructor

Properties

Readonly id

id: string

Protected local

local: Atom<T>

parent

parent: IAtom<any>

Protected selfUpdate

selfUpdate: boolean

Accessors

value

  • get value(): T
  • set value(val: T): void

Methods

addWatch

  • addWatch(id: string, fn: Watch<T>): boolean

deref

  • deref(): T

notifyWatches

  • notifyWatches(oldState: T, newState: T): void

release

  • release(): boolean

removeWatch

  • removeWatch(id: string): boolean

reset

  • reset(val: T): T

resetIn

  • resetIn(path: Path0, val: T): T
  • resetIn<A>(path: Path1<T, A>, val: PathVal<T, []>): T
  • resetIn<A, B>(path: Path2<T, A, B>, val: PathVal<T, []>): T
  • resetIn<A, B, C>(path: Path3<T, A, B, C>, val: PathVal<T, []>): T
  • resetIn<A, B, C, D>(path: Path4<T, A, B, C, D>, val: PathVal<T, []>): T
  • resetIn<A, B, C, D, E>(path: Path5<T, A, B, C, D, E>, val: PathVal<T, []>): T
  • resetIn<A, B, C, D, E, F>(path: Path6<T, A, B, C, D, E, F>, val: PathVal<T, []>): T
  • resetIn<A, B, C, D, E, F, G>(path: Path7<T, A, B, C, D, E, F, G>, val: PathVal<T, []>): T
  • resetIn<A, B, C, D, E, F, G, H>(path: Path8<T, A, B, C, D, E, F, G, H>, val: PathVal<T, []>): T
  • resetIn<A, B, C, D, E, F, G, H>(path: DeepPath<T, A, B, C, D, E, F, G, H>, val: any): T

resetInUnsafe

  • resetInUnsafe(path: Path, val: any): T

swap

  • swap(fn: SwapFn<T, T>, ...args: any[]): T

swapIn

  • swapIn<A>(path: Path0, fn: SwapFn<T, T>, ...args: any[]): T
  • swapIn<A>(path: Path1<T, A>, fn: SwapFn<OptPathVal<T, []>, PathVal<T, []>>, ...args: any[]): T
  • swapIn<A, B>(path: Path2<T, A, B>, fn: SwapFn<OptPathVal<T, []>, PathVal<T, []>>, ...args: any[]): T
  • swapIn<A, B, C>(path: Path3<T, A, B, C>, fn: SwapFn<OptPathVal<T, []>, PathVal<T, []>>, ...args: any[]): T
  • swapIn<A, B, C, D>(path: Path4<T, A, B, C, D>, fn: SwapFn<OptPathVal<T, []>, PathVal<T, []>>, ...args: any[]): T
  • swapIn<A, B, C, D, E>(path: Path5<T, A, B, C, D, E>, fn: SwapFn<OptPathVal<T, []>, PathVal<T, []>>, ...args: any[]): T
  • swapIn<A, B, C, D, E, F>(path: Path6<T, A, B, C, D, E, F>, fn: SwapFn<OptPathVal<T, []>, PathVal<T, []>>, ...args: any[]): T
  • swapIn<A, B, C, D, E, F, G>(path: Path7<T, A, B, C, D, E, F, G>, fn: SwapFn<OptPathVal<T, []>, PathVal<T, []>>, ...args: any[]): T
  • swapIn<A, B, C, D, E, F, G, H>(path: Path8<T, A, B, C, D, E, F, G, H>, fn: SwapFn<OptPathVal<T, []>, PathVal<T, []>>, ...args: any[]): T
  • swapIn<A, B, C, D, E, F, G, H>(path: DeepPath<T, A, B, C, D, E, F, G, H>, fn: SwapFn<any, any>, ...args: any[]): T

swapInUnsafe

  • swapInUnsafe(path: Path, fn: SwapFn<any, any>, ...args: any[]): T

Generated using TypeDoc