State Change Trigger pattern

When an svc_expr service has states, the notify operations on the service can be conditionalized to trigger on state changes.

In the example in Table 1, a notify operation is triggered as soon as the Count state variable exceeds 5.

Table 1. State Change Trigger
Example Description
<mix name="Mix">
  <service name="Expr"  
    <prop name="expr.state"    

  <notify name="myNotify"  
    <prop name="expr.state"    
    <prop name="expr.src"    
  Count > 5.  
Note: Do not manually type the <![CDATA...]]> delimiters. The Editor automatically renders text content as XML CDATA sections.
The myNotify operation specifies the Expr service as a client. The Expr service has Count as a state variable.

When the Count state variable is changed by any other operation, the expression list in the myNotify operation is evaluated and the notify is triggered.

Note: The old value of the Count state variable is available in the OldCount variable which can be used by any expression in the expressions list.

If the final expression value is true, that is, Count is bigger than 5, the notify is fired.

If the value of the final expression is any value other than boolean true, the notify event is not fired

The myNotify operation ignores all other state variables that may exist on the mix. This operation is only listening for changes to the Count variable and is only triggered whenever this variable changes.

If more than one variable is specified in the expr.state property, then the notify is triggered by a change in any one of those variables.