Lime Web Components API Documentation - v6.27.0
    Preparing search index...

    Interface UserDataRepository

    Handle fetching and saving user specific data, e.g. settings or other state data that should persist between sessions

    interface UserDataRepository {
        get<T = any>(key: string): T;
        has(key: string): boolean;
        set<T = any>(key: string, data?: T): Promise<void>;
        subscribe(
            callback: (...args: unknown[]) => void,
            options?: StateOptions,
        ): () => void;
    }

    Hierarchy (View Summary)

    Index

    Methods

    • Get user data

      Type Parameters

      • T = any

      Parameters

      • key: string

        name of the key containing the data

      Returns T

      the data

    • Check if user data exists

      Parameters

      • key: string

        name of the key containing the data

      Returns boolean

      true if user data exists

    • Set user data

      Type Parameters

      • T = any

      Parameters

      • key: string

        name of the key for the data

      • Optionaldata: T

        the data to save, will delete the data if undefined

      Returns Promise<void>

      a promise that will be resolved when the data has been saved

    • Subscribe to state changes with optional transformation and filtering.

      The subscription will immediately invoke the callback with the current state (if any), then continue to call it whenever the state changes. The map and filter options allow you to transform and selectively receive updates.

      Parameters

      • callback: (...args: unknown[]) => void

        Function called with state updates (after map/filter applied)

      • Optionaloptions: StateOptions

        Optional transformations and filters for the subscription

      Returns () => void

      Unsubscribe function - call this to stop receiving updates

      • Map functions are applied sequentially to transform the state
      • Filter functions must all return true for the callback to be invoked
      • Functions in map/filter arrays are bound to the component instance
      • Always store and call the unsubscribe function when component is destroyed
      // Basic subscription
      const unsubscribe = repository.subscribe((state) => {
      console.log('State updated:', state);
      });

      // With transformations
      const unsubscribe = repository.subscribe(
      (userName) => console.log('User:', userName),
      { map: [(state) => state.user?.name] }
      );