| Package | org.pranaframework.cairngorm |
| Class | public class EventSequence |
EventSequence represents a sequence of events to be chained.
This allows you to chain commands by chaining the events that are dispatched
to the FrontController in order to execute a command.
Using an event sequence, the commands must not extend
SequenceCommand and hence should not set up a nextEvent and
dispatch it. This means that your commands can be used in a number of different
sequence scenarios without letting the commands know they are chained.
The sequencing works by setting up a trigger for an event, based on a property change in an object. This property change will normally be executed by a command.
var sequence:EventSequence = new EventSequence(); sequence.addSequenceEvent(LoadSessionEvent, ["4562-54289778-56985412"]); sequence.addSequenceEvent(LoadExamEvent, [new Property(ModelLocator.getInstance(), "session", "examId")], [new Property(ModelLocator.getInstance(), "session")]); sequence.addSequenceEvent(LoadCandidateEvent, [new Property(ModelLocator.getInstance(), "session", "candidateId")], [new Property(ModelLocator.getInstance(), "exam")]); sequence.dispatch();
In this example, 3 events are chained. (This sequence is used to load the session of an exam, the exam itself and the candidate)
The first event is the LoadSessionEvent that gets
the id of a session as its constructor argument. The command that is
executed by this event will fetch an exam session and store it in the
session property of the ModelLocator. Since
this is the first event, it does not define any triggers for the next event.
The second event is the LoadExamEvent. This event takes
the id of the exam as its constructor argument, fetches an exam and stores
it in the exam property of the ModelLocator.
Notice the 3rd argument that defines the trigger for this event. It is
defined a Property object that contains a reference to the
session property in the ModelLocator. This means
that this event will be dispatched when the session property has been set.
The examId is also passed in as a property and will be evaluated when the
sequence creates the next event.
The third event is the LoadCandidateEvent. This event takes
the session.candidateId as its constructor argument and will be dispatched
when the exam property is set on the ModelLocator.
| Method | Defined by | ||
|---|---|---|---|
|
Creates a new EventSequence
| EventSequence | ||
|
addSequenceEvent(eventClass:Class, parameters:Array = null, triggers:Array = null):void
Adds an event to this sequence.
| EventSequence | ||
|
cancel():void
In case of failure, this cancels the 'on deck' sequence
| EventSequence | ||
|
dispatch():void
Starts dispatching this event sequence.
| EventSequence | ||
| EventSequence | () | constructor |
public function EventSequence()Creates a new EventSequence
| addSequenceEvent | () | method |
public function addSequenceEvent(eventClass:Class, parameters:Array = null, triggers:Array = null):voidAdds an event to this sequence.
ParameterseventClass:Class — the class of the event (must be a subclass of CairngormEvent)
|
|
parameters:Array (default = null) — the arguments that will be passed to the event's constructor
|
|
triggers:Array (default = null) — the triggers that will cause the next event to be dispatched
|
| cancel | () | method |
public function cancel():voidIn case of failure, this cancels the 'on deck' sequence
| dispatch | () | method |
public function dispatch():voidStarts dispatching this event sequence.