Replace the entire context data with new values. All expressions will automatically re-evaluate against the new context.
Complete new context data to replace existing data
evaluator.setContextData({ temperature: 75, humidity: 40 });
Update a nested property in the context data using dot notation. This method safely updates nested properties without replacing the entire object structure.
Dot-separated path to the nested property (e.g., 'sensors.humidity', 'config.thresholds.temp')
The new value to set at the nested path
evaluator.updateNestedValue('sensors.humidity', 60);
Add a KOS model to the evaluation context. The model's observable properties will be accessible via dotted notation and expressions will automatically re-evaluate when the model's data changes.
The context key to store the model under
Any KOS model instance (must be observable)
const sensorModel = SensorModel.instance('main-sensor').build();
evaluator.addModelToContext('sensor', sensorModel);
evaluator.addExpression('isCritical', 'sensor.temperature > 80');
Add a named expression that will be automatically evaluated against context data. The expression will re-evaluate whenever its dependencies in the context change.
Unique identifier for this expression (type-safe when using generic)
JavaScript-like expression string
If the expression has invalid syntax
evaluator.addExpression('isHot', 'temperature > 80');
Get the cached result of an expression without triggering re-evaluation. This is useful for dependency tracking in effects where you want to avoid creating reactive chains through the expression evaluation.
The expression name to get the cached result for
The last cached result, or undefined if expression doesn't exist
const cached = evaluator.getCachedExpressionValue('myExpression');
Create an anonymous reactive expression and return its generated ID. The expression becomes fully reactive and can be accessed via the returned ID.
JavaScript-like expression string
Generated UUID that can be used to access the expression via getExpressionValue(id) or results[id]
const tempCheckId = evaluator.createExpression('temperature > 75');
const result = evaluator.getExpressionValue(tempCheckId);
KOS Expression Evaluator Model - Reactive expression evaluation with dynamic context and type-safe named expressions.
This model provides a reactive expression evaluation system that automatically re-evaluates expressions when their context data changes. Perfect for business rules, computed values, and conditional logic that needs to stay synchronized with changing data.
Key Features
Example: Basic Usage
Use Declared Type