Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Replicache

Hierarchy

  • Replicache

Implements

Index

Constructors

constructor

  • new Replicache(__namedParameters: { batchURL: string; dataLayerAuth: string; diffServerAuth: string; diffServerURL: string; name: string; pushDelay: number; repmInvoker: undefined | { invoke: REPMInvoke }; syncInterval: null | number; wasmModule: undefined | string | Request | URL | Response | ArrayBufferView | ArrayBuffer | Module }): Replicache
  • Parameters

    • __namedParameters: { batchURL: string; dataLayerAuth: string; diffServerAuth: string; diffServerURL: string; name: string; pushDelay: number; repmInvoker: undefined | { invoke: REPMInvoke }; syncInterval: null | number; wasmModule: undefined | string | Request | URL | Response | ArrayBufferView | ArrayBuffer | Module }
      • batchURL: string
      • dataLayerAuth: string
      • diffServerAuth: string
      • diffServerURL: string
      • name: string
      • pushDelay: number
      • repmInvoker: undefined | { invoke: REPMInvoke }
      • syncInterval: null | number
      • wasmModule: undefined | string | Request | URL | Response | ArrayBufferView | ArrayBuffer | Module

    Returns Replicache

Properties

getDataLayerAuth

getDataLayerAuth: (() => MaybePromise<string | null | undefined>) | null | undefined = null

This gets called when we get an HTTP unauthorized from the client view or the batch endpoint. Set this to a function that will ask your user to reauthenticate.

onSync

onSync: ((syncing: boolean) => void) | null = null

pushDelay

pushDelay: number

The delay between when a change is made to Replicache and when Replicache attempts to push that change.

Accessors

closed

  • get closed(): boolean
  • Returns boolean

online

  • get online(): boolean
  • Returns boolean

syncInterval

  • get syncInterval(): number | null
  • set syncInterval(duration: number | null): void
  • The duration between each sync. Set this to null to prevent syncing in the background.

    Returns number | null

  • The duration between each sync. Set this to null to prevent syncing in the background.

    Parameters

    • duration: number | null

    Returns void

Methods

close

  • close(): Promise<void>
  • Returns Promise<void>

get

  • get(key: string): Promise<JSONValue | undefined>
  • Get a single value from the database.

    Parameters

    • key: string

    Returns Promise<JSONValue | undefined>

has

  • has(key: string): Promise<boolean>
  • Determines if a single key is present in the database.

    Parameters

    • key: string

    Returns Promise<boolean>

query

  • Query is used for read transactions. It is recommended to use transactions to ensure you get a consistent view across multiple calls to get, has and scan.

    Type parameters

    • R

    Parameters

    Returns Promise<R>

register

  • register<Return, Args>(name: string, mutatorImpl: MutatorImpl<Return, Args>): Mutator<Return, Args>
  • Registers a mutator, which is used to make changes to the data.

    Replays

    Mutators run once when they are initially invoked, but they might also be replayed multiple times during sync. As such mutators should not modify application state directly. Also, it is important that the set of registered mutator names only grows over time. If Replicache syncs and needed mutator is not registered, it will substitute a no-op mutator, but this might be a poor user experience.

    Server application

    During sync, a description of each mutation is sent to the server's batch endpoint where it is applied. Once the mutation has been applied successfully, as indicated by the client view's lastMutationId field, the local version of the mutation is removed. See the design doc for additional details on the sync protocol.

    Transactionality

    Mutators are atomic: all their changes are applied together, or none are. Throwing an exception aborts the transaction. Otherwise, it is committed. As with [query] and [subscribe] all reads will see a consistent view of the cache while they run.

    Type parameters

    • Return: JSONValue | void

    • Args: JSONValue

    Parameters

    • name: string
    • mutatorImpl: MutatorImpl<Return, Args>

    Returns Mutator<Return, Args>

scan

  • scan(__namedParameters?: { indexName: undefined | string; limit: undefined | number; prefix: string; start: undefined | ScanBound }): ScanResult
  • Gets many values from the database. This returns a Result which implements AsyncIterable. It also has methods to iterate over the keys and entries.

    Parameters

    • Default value __namedParameters: { indexName: undefined | string; limit: undefined | number; prefix: string; start: undefined | ScanBound } = {}
      • indexName: undefined | string
      • limit: undefined | number
      • prefix: string
      • start: undefined | ScanBound

    Returns ScanResult

scanAll

  • scanAll(options?: ScanOptions): Promise<[][]>
  • Convenience form of scan() which returns all the results as an array.

    Parameters

    • Default value options: ScanOptions = {}

    Returns Promise<[][]>

subscribe

  • subscribe<R, E>(body: (tx: ReadTransaction) => Promise<R>, __namedParameters: { onData: (result: R) => void; onDone: undefined | (() => void); onError: undefined | ((error: E) => void) }): () => void
  • Subcribe to changes to the underlying data. Every time the underlying data changes onData is called. The function is also called once the first time the subscription is added. There is currently no guarantee that the result of this subscription changes and it might get called with the same value over and over.

    This returns a function that can be used to cancel the subscription.

    If an error occurs in the body the onError function is called if present. Otherwise, the error is thrown.

    Type parameters

    • R

    • E

    Parameters

    • body: (tx: ReadTransaction) => Promise<R>
    • __namedParameters: { onData: (result: R) => void; onDone: undefined | (() => void); onError: undefined | ((error: E) => void) }
      • onData: (result: R) => void
          • (result: R): void
          • Parameters

            • result: R

            Returns void

      • onDone: undefined | (() => void)
      • onError: undefined | ((error: E) => void)

    Returns () => void

      • (): void
      • Returns void

sync

  • sync(): Promise<void>
  • Synchronizes this cache with the server. New local mutations are sent to the server, and the latest server state is applied to the cache. Any local mutations not included in the new server state are replayed. See the Replicache design document for more information on sync: https://github.com/rocicorp/replicache/blob/master/design.md

    Returns Promise<void>

Generated using TypeDoc