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

    Interface ConditionRegistryBeta

    Central registry for managing conditional evaluation rules across the application.

    The ConditionRegistry acts as a global repository for Condition instances, allowing different parts of the application to register, retrieve, and evaluate conditions. This is particularly useful for:

    • Controlling action visibility based on object state
    • Implementing permission-based UI rendering
    • Creating dynamic, context-aware interfaces
    • Sharing reusable business logic across components

    Components typically access the registry via the platform service and register their conditions when the application initializes. Conditions can be added and removed dynamically, allowing for flexible runtime configuration.

    Registering and using conditions in a component

    const registry = platform.get(PlatformServiceName.ConditionRegistry);

    const canWinDeal = {
    id: 'deal.can-win',
    type: 'limeobject',
    evaluate: (deal) => deal.dealstatus === 'proposal' && deal.value > 0
    };

    const canLoseDeal = {
    id: 'deal.can-lose',
    type: 'limeobject',
    evaluate: (deal) => deal.dealstatus !== 'lost' && deal.dealstatus !== 'won'
    };

    registry.addCondition(canWinDeal);
    registry.addCondition(canLoseDeal);

    const actions = [
    {
    label: 'Mark as Won',
    icon: 'trophy',
    command: { name: 'win-deal' },
    condition: registry.getCondition('deal.can-win')
    },
    {
    label: 'Mark as Lost',
    icon: 'times',
    command: { name: 'lose-deal' },
    condition: registry.getCondition('deal.can-lose')
    }
    ];

    const availableActions = actions.filter(action => {
    return !action.condition || action.condition.evaluate(deal);
    });

    Use RuleRegistry instead.

    interface ConditionRegistry {
        addCondition<T extends Condition<unknown> = Condition<unknown>>(
            condition: T,
            metadata?: ConfigMetadata,
        ): void;
        getAllMetadata?(): ConditionMetadata[];
        getCondition(id: string): Condition;
        getConditions(): Condition<unknown>[];
        hasCondition(id: string): boolean;
        removeCondition(condition: Condition): void;
    }
    Index

    Methods

    • Beta

      Registers a new condition in the registry.

      The condition's ID must be unique across all registered conditions. If a condition with the same ID already exists, this method throws an error. It's recommended to register conditions during application startup.

      Type Parameters

      Parameters

      Returns void

      Error if a condition with the same ID already exists in the registry.

      const isActive: LimeObjectCondition = {
      id: 'deal.is-active',
      type: 'limeobject',
      evaluate: (deal) => deal.dealstatus === 'active'
      };

      registry.addCondition(isActive);
    • Beta

      Retrieves metadata for all conditions in the registry.

      This method returns an array of metadata objects containing information about all registered conditions, including their IDs, types, and configuration details.

      Returns ConditionMetadata[]

      An array of condition metadata objects, or undefined if not supported by the registry implementation.

      const allMetadata = registry.getAllMetadata();
      if (allMetadata) {
      allMetadata.forEach(meta => {
      console.log(`Condition: ${meta.id}, Type: ${meta.type}, Title: ${meta.title}`);
      });
      }
    • Beta

      Retrieves a specific condition by its unique identifier.

      If no condition with the given ID exists, this method throws an error. Use ConditionRegistry.hasCondition first if you need to check for existence.

      Parameters

      • id: string

        The unique identifier of the condition to retrieve.

      Returns Condition

      The condition with the specified ID.

      Error if no condition with the given ID exists in the registry.

      const canWin = registry.getCondition('deal.can-win');
      const isEligible = canWin.evaluate(dealObject);

      Safe retrieval with type checking

      const condition = registry.getCondition('deal.is-active');
      if (isLimeObjectCondition(condition)) {
      const result = condition.evaluate(myDeal);
      }
    • Beta

      Retrieves all registered conditions.

      This method returns a list of all conditions currently in the registry, regardless of their type. This can be useful for debugging, inspection, or building dynamic UIs that need to enumerate available conditions.

      Returns Condition<unknown>[]

      An array of all registered conditions.

      const allConditions = registry.getConditions();
      console.log(`Found ${allConditions.length} conditions`);

      const limeObjectConditions = allConditions.filter(
      c => c.type === 'limeobject'
      );
    • Beta

      Checks whether a condition with the given ID exists in the registry.

      This method is useful for defensive programming, allowing you to verify that a condition exists before attempting to retrieve or remove it.

      Parameters

      • id: string

        The unique identifier of the condition to check.

      Returns boolean

      true if a condition with the ID exists, false otherwise.

      if (registry.hasCondition('deal.can-win')) {
      const condition = registry.getCondition('deal.can-win');
      const canWin = condition.evaluate(deal);
      }
    • Beta

      Removes a condition from the registry.

      The condition is identified by its ID. If no condition with the given ID exists in the registry, this method throws an error.

      Parameters

      • condition: Condition

        The condition to remove. Must exist in the registry.

      Returns void

      Error if the condition's ID does not exist in the registry.

      const condition = registry.getCondition('deal.is-active');
      registry.removeCondition(condition);

      Safe removal with existence check

      if (registry.hasCondition('deal.is-active')) {
      registry.removeCondition(registry.getCondition('deal.is-active'));
      }