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.

Example

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

See

Hierarchy

  • ConditionRegistry

Methods

  • 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.

    Throws

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

    Example

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

    registry.addCondition(isActive);

    Parameters

    • condition: Condition<unknown>

      The condition to register. Must have a unique ID.

    Returns any

  • Retrieves a specific condition by its unique identifier.

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

    Returns

    The condition with the specified ID.

    Throws

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

    Example

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

    Example

    Safe retrieval with type checking

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

    Parameters

    • id: string

      The unique identifier of the condition to retrieve.

    Returns Condition<unknown>

  • 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

    An array of all registered conditions.

    Example

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

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

    Returns Condition<unknown>[]

  • 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.

    Returns

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

    Example

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

    Parameters

    • id: string

      The unique identifier of the condition to check.

    Returns boolean

  • 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.

    Throws

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

    Example

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

    Example

    Safe removal with existence check

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

    Parameters

    • condition: Condition<unknown>

      The condition to remove. Must exist in the registry.

    Returns any