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

    Interface StateRepository

    Base interface for repositories that provide reactive state subscriptions.

    StateRepository is the foundation for all reactive data sources in the platform. Repositories like ConfigRepository, LimeObjectRepository, FilterRepository, etc. extend this interface to provide subscription-based access to their data.

    The subscription pattern allows components to react to data changes automatically, ensuring UI stays synchronized with the underlying application state.

    class MyComponent {
    @State()
    @SelectCurrentUser({
    map: [(user) => user?.fullname],
    filter: [(name) => name !== undefined]
    })
    private userName: string;

    @State()
    @SelectCurrentLimeobject({
    map: [(obj) => obj?.properties?.name]
    })
    private objectName: string;
    }
    const unsubscribe = repository.subscribe(
    (state) => {
    console.log('State updated:', state);
    },
    {
    map: [(state) => ({ user: state.user, language: state.language })],
    filter: [(state) => state.user !== null]
    }
    );

    // Remember to unsubscribe when component is destroyed
    unsubscribe();
    interface StateRepository {
        subscribe(
            callback: (...args: unknown[]) => void,
            options?: StateOptions,
        ): () => void;
    }

    Hierarchy (View Summary)

    Index

    Methods

    Methods

    • 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] }
      );