Lime Web Components API Documentation - v7.4.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.

    import {
    Action,
    Command,
    LimeObjectCondition,
    PlatformServiceName,
    } from '@limetech/lime-web-components';

    @Command({ id: 'win-deal' })
    class WinDealCommand {
    dealId: number;
    }

    @Command({ id: 'lose-deal' })
    class LoseDealCommand {
    dealId: number;
    }

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

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

    const canLoseDeal: LimeObjectCondition = {
    id: 'deal.can-lose',
    type: 'limeobject',
    evaluate: (deal) => {
    const status = deal.getValue('dealstatus');

    return status !== 'lost' && status !== 'won';
    },
    };

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

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

    const repository = platform.get(PlatformServiceName.LimeObjectRepository);
    const deal = repository.getObject('deal', 1234);

    const availableActions = actions.filter(
    (action) => !action.condition || (!!deal && 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.

      import {
      LimeObjectCondition,
      PlatformServiceName,
      } from '@limetech/lime-web-components';

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

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

      registry.addCondition(isActive, {
      title: 'Deal is active',
      description: 'True while the deal is still being worked on',
      });
    • 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.

      import { PlatformServiceName } from '@limetech/lime-web-components';

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

      const allMetadata = registry.getAllMetadata?.();
      if (allMetadata) {
      for (const meta of allMetadata) {
      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.

      import { PlatformServiceName } from '@limetech/lime-web-components';

      const registry = platform.get(PlatformServiceName.ConditionRegistry);
      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const deal = repository.getObject('deal', 1234);

      const canWin = registry.getCondition('deal.can-win');
      const isEligible = !!deal && canWin.evaluate(deal);
      import {
      isLimeObjectCondition,
      PlatformServiceName,
      } from '@limetech/lime-web-components';

      const registry = platform.get(PlatformServiceName.ConditionRegistry);
      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const deal = repository.getObject('deal', 1234);

      const condition = registry.getCondition('deal.is-active');
      if (deal && isLimeObjectCondition(condition)) {
      const result = condition.evaluate(deal);
      }
    • 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.

      import { PlatformServiceName } from '@limetech/lime-web-components';

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

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

      const limeObjectConditions = allConditions.filter(
      (condition) => condition.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.

      import { PlatformServiceName } from '@limetech/lime-web-components';

      const registry = platform.get(PlatformServiceName.ConditionRegistry);
      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const deal = repository.getObject('deal', 1234);

      if (deal && 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.

      import { PlatformServiceName } from '@limetech/lime-web-components';

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

      const condition = registry.getCondition('deal.is-active');
      registry.removeCondition(condition);
      import { PlatformServiceName } from '@limetech/lime-web-components';

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

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