0
@@ -41,7 +41,17 @@ for those will be:
0
after[state]Action: Fires just after the state becomes current
0
exit[state]Action: Fires on the previous state just after the new
0
state becomes current (i.e. when you leave this state)
0
+Without specifying a persistence object (service layer), the state property
0
+is updated but not persisted to the database. Obviously, this has a limiting
0
+effect on events. An after event will fire after the state is updated even
0
+though it will not be changed in the database.
0
+To get the proper use of the event callbacks, you should pass in a persistence
0
+object which will be passed the the business object and is responsible for
0
@@ -50,18 +60,30 @@ for those will be:
0
<cffunction name="setState" ...
0
+ <!--- This is optional, but needed for persistence --->
0
+ <cfcomponent displayname="OrderService" extends="shade.StateMachine" output="false">
0
+ <cffunction name="save">
0
+ <cfarguments name="order" ...
0
<cfcomponent displayname="StatefulOrder" extends="shade.StateMachine" output="false">
0
<cfset instance = structNew() />
0
<cffunction name="init" access="public" returntype="any" output="false">
0
<cfargument name="order" required="true" />
0
+ <cfargument name="persistenceObject" required="false" />
0
Call super passing the original business object and the initial state.
0
You can also pass the method to set the state in your business object (without
0
the get/set in front of it). It defaults to 'State' which would them
0
assume that you business object had getState() and setState() methods.
0
- <cfset super.init(arguments.order, 'new') />
0
+ <cfset super.init(arguments.order, 'new', 'State', arguments.persistenceObject, 'save') />
0
+ or <cfset super.init(arguments.order, 'new') /> if there is no persistence object