mobx-sentinel API doc
    Preparing search index...

    Validator for handling synchronous and asynchronous validations

    • Supports both sync and async validation handlers
    • Tracks validation state (isValidating)
    • Provides error access by key path
    • Supports nested validators

    Type Parameters

    • T
    Index

    Properties

    defaultDelayMs: number = 100
    id: string = ...

    Accessors

    Methods

    • Get a validator instance for the target object.

      Type Parameters

      • T extends object

      Parameters

      • target: T

      Returns Validator<T>

      • Returns existing instance if one exists for the target
      • Creates new instance if none exists
      • Instances are cached and garbage collected with their targets

      TypeError if the target is not an object.

    • Add an async handler

      Type Parameters

      • Expr

      Parameters

      • expr: () => Expr

        The expression to observe

      • handler: AsyncHandler<T, NoInfer<Expr>>

        The async handler to call when the expression changes

      • Optionalopt: HandlerOptions<NoInfer<Expr>>

        The handler options

      Returns () => void

      A function to remove the handler

      • Handler runs immediately when added for initial validation
      • Handler is called when the watched expression changes
      • Changes are throttled by default delay
      • Provides abort signal for cancellation
      • Previous validations are aborted when new ones start
    • Add a sync handler

      Parameters

      Returns () => void

      A function to remove the handler

      • Handler runs immediately when added for initial validation
      • Handler is called when observable expressions within it change
      • Changes are throttled by default delay
    • Find errors for the key path

      • Can do exact or prefix matching
      • Returns all errors that match the key path
      • Includes errors from nested validators when using prefix match

      Parameters

      • searchKeyPath: KeyPath
      • prefixMatch: boolean = false

      Returns Generator<[keyPath: KeyPath, error: ValidationError], void, unknown>

    • Reset the validator

      Use with caution.
      Since validation is reactive, errors won't reappear until you make some changes.

      Returns void