public
Description: Shade is a state machine (or workflow) engine for ColdFusion business objects.
Homepage:
Clone URL: git://github.com/ryanwood/shade.git
Updated README
ryanwood (author)
Mon Oct 13 07:39:46 -0700 2008
commit  b2457504eeba4e0ece295659fa26bc6ad909fba0
tree    0f86abde1f9ddcba0121b546234378d0f66a8e05
parent  0bdacba1386989f5809b763877b67038f0bf609a
0
...
41
42
43
44
 
 
 
 
 
 
 
 
 
 
 
45
46
47
...
50
51
52
 
 
 
 
 
 
 
 
53
54
55
56
57
 
58
59
60
61
62
63
64
 
 
 
 
65
66
67
...
41
42
43
 
44
45
46
47
48
49
50
51
52
53
54
55
56
57
...
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
 
83
84
85
86
87
88
89
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
-                          
0
+
0
+-- Persistence --
0
+
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
+
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
+saving it.               
0
 
0
 === EXAMPLE ===
0
 
0
@@ -50,18 +60,30 @@ for those will be:
0
     <cffunction name="setState" ...
0
   </cfcomponent>
0
 
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
+       ...perform the save
0
+    </cffunction>
0
+  </cfcomponent>
0
+
0
   <cfcomponent displayname="StatefulOrder" extends="shade.StateMachine" output="false">
0
     <cfset instance = structNew() />
0
     
0
     <cffunction name="init" access="public" returntype="any" output="false">
0
       <cfargument name="order" required="true" />
0
+      <cfargument name="persistenceObject" required="false" />  
0
       <!--- 
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
       --->
0
-      <cfset super.init(arguments.order, 'new') />
0
+      <cfset super.init(arguments.order, 'new', 'State', arguments.persistenceObject, 'save') />
0
+      <!---
0
+      or <cfset super.init(arguments.order, 'new') /> if there is no persistence object 
0
+      --->
0
       <cfreturn this />
0
     </cffunction>
0
       

Comments