Expressions
The Builder and DevCore framework use JavaScript-like expressions throughout the system to provide flexible control over processing logic and application UI behavior. These expressions enable dynamic configuration and conditional logic without requiring code changes.
Expression Usage
Expressions are used in the following contexts:
UI Control
- View.enable - Enable or disable specific views based on conditions
- Widget.show - Control widget visibility dynamically
System Logic
- Software Update Policy - Determine if updates should be applied to specific devices
- Automated Actions - Control conditional logic in if/then/else statements
Expression Context
Expressions are JavaScript-style statements that resolve to boolean results. They have access to context variables that vary depending on the usage context.
Context Variables
The following variables are available in expression contexts:
Variable | Type | Description | Context |
---|---|---|---|
agent | String | Browser user agent string | UI contexts |
dark | Boolean | True if in dark mode | UI contexts |
design | Boolean | True if widget is in design mode | Widget contexts |
desktop | Boolean | True if running on desktop (not mobile) | UI contexts |
framed | Boolean | True if board is framing widgets | Widget contexts |
height | Number | Browser height dimension (window.innerHeight) | UI contexts |
language | String | Browser language setting (navigator.language) | UI contexts |
light | Boolean | True if in light mode | UI contexts |
mobile | Boolean | True if running on mobile device (≤ 640px width) | UI contexts |
value | Various | Widget data or input value | Widget contexts |
width | Number | Browser width dimension (window.innerWidth) | UI contexts |
Expression Examples
Basic Conditions
javascript
// Simple value comparison
value > 0
value == "active"
value != null
// Boolean conditions
dark && mobile
light || desktop
Device-Based Conditions
javascript
// Screen size conditions
width < 640 // Mobile devices
width >= 640 && width <= 1024 // Tablet devices
width > 1024 // Desktop devices
// Combined device conditions
mobile && language == "en" // English mobile users
desktop && !dark // Desktop light mode
String Operations
javascript
// String matching
agent ^= "Chrome" // User agent starts with "Chrome"
language $= "US" // Language ends with "US"
value >< "error" // Value contains "error"
// Regular expressions
agent =~ /Chrome|Firefox/ // Chrome or Firefox browsers
language =~ /^en/ // English language variants
Expression Operators
Arithmetic Operators
+
-
*
/
%
^
(
)
Comparison Operators
==
!=
<
<=
>
>=
Logical Operators
&&
||
!
String Operators
Operator | Description |
---|---|
^= | Starts with |
^!= | Does not start with |
$= | Ends with |
$!= | Does not end with |
>< | Contains |
<> | Does not contain |
Regular Expression Support
Regular expressions (delimited by slashes) can be used with equality operators:
javascript
agent =~ /Mobile/ // Mobile user agent
value =~ /^[0-9]+$/ // Numeric values only
Expression Limitations
Performance Constraints
- Term Limit - Maximum of 50 terms per expression
- Runtime Protection - Prevents denial of service attacks
- Evaluation Timeout - Expressions must complete within reasonable time
Type Support
The expression engine supports:
- Numbers (integers and floating-point)
- Boolean values (true/false)
- String literals (quoted strings)
- Regular expressions (slash-delimited)
- Null values
Best Practices
Performance Optimization
- Keep expressions simple and focused
- Avoid complex nested conditions when possible
- Use appropriate operators for string comparisons
- Test expressions with expected data ranges
Maintainability
- Document complex expressions clearly
- Use descriptive variable names in context
- Group related conditions with parentheses
- Avoid overly complex regular expressions
Security Considerations
- Validate expression inputs where possible
- Be aware of term limits for complex expressions
- Consider performance impact of frequent evaluations
Common Use Cases
Responsive Design
javascript
// Show widget only on desktop
desktop && width > 1024
// Hide widget on mobile
!mobile
Feature Toggles
javascript
// Enable feature for specific language
language == "en" || language == "fr"
// Show advanced features for power users
value == "admin" || value == "power"
Conditional Updates
javascript
// Update policy for production devices
value.environment == "production" && value.version < "2.0"
// Emergency updates only
value.priority == "critical"
Debugging Expressions
Testing Approaches
- Use simple test cases to validate logic
- Test with different context variable values
- Verify boolean results match expectations
- Check for edge cases with null or undefined values
Common Issues
- Incorrect operator precedence
- Missing parentheses in complex conditions
- Type mismatches in comparisons
- Regular expression syntax errors