Skip to content

Instantly share code, notes, and snippets.

@robertpenner
Created October 31, 2011 14:15
Show Gist options
  • Save robertpenner/1327579 to your computer and use it in GitHub Desktop.
Save robertpenner/1327579 to your computer and use it in GitHub Desktop.
Command Flow DSL Comparison
const saveFlow:Flow = new Flow(
{
saveSeq : new Sequence(
[
new Attempt(ValidateChanges).guard(NotQuitting).fail(ShowError),
new Attempt(ConfirmWithUser),
new Execute(BlockQuitting),
new Attempt(SaveData).fail(saveDataErrorSeq),
new Execute(StoreSavedData),
new Execute(UnblockQuitting)
]),
saveDataErrorSeq : new Sequence(
[
new Execute(ProcessSaveError),
new Execute(UnblockQuitting)
]),
deleteSeq : new Sequence(
[
new Attempt(ValidateDelete).guard(NotQuitting).fail(ShowError),
new Attempt(ConfirmWithUser),
new Execute(BlockQuitting),
new Attempt(DeleteData).fail(deleteDataErrorSeq),
new Execute(UpdateDeletedData),
new Execute(UnblockQuitting)
]),
deleteDataErrorSeq : new Sequence(
[
new Execute(ProcessDeletionError),
new Execute(UnblockQuitting)
]),
cancelSeq : new Sequence(
[
new Attempt(CheckForChanges).guard(NotQuitting).fail(ShowAdvice),
new Attempt(ConfirmWithUser),
new Execute(RevertData)
])
});
<?xml version="1.0" encoding="utf-8"?>
<Flow xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="org.roburntlegs.*">
<children>
<Sequence id="saveSeq">
<Attempt action="{ValidateChanges}" guard="{NotQuitting}" fail="{ShowError}"/>
<Attempt action="{ConfirmWithUser}"/>
<Execute action="{BlockQuitting}"/>
<Attempt action="{SaveData}" fail="{saveDataErrorSeq}" />
<Execute action="{StoreSavedData}"/>
<Execute action="{UnblockQuitting}"/>
</Sequence>
<Sequence id="saveDataErrorSeq">
<Execute action="{ProcessSaveError}"/>
<Execute action="{UnblockQuitting}"/>
</Sequence>
<Sequence id="deleteSeq">
<Attempt action="{ValidateDelete}" guard="{NotQuitting}" fail="{ShowError}"/>
<Attempt action="{ConfirmWithUser}"/>
<Execute action="{BlockQuitting}"/>
<Attempt action="{DeleteData}" fail="{deleteDataErrorSeq}" />
<Execute action="{UpdateDeletedData}"/>
<Execute action="{UnblockQuitting}"/>
</Sequence>
<Sequence id="deleteDataErrorSeq">
<Execute action="{ProcessDeletionError}"/>
<Execute action="{UnblockQuitting}"/>
</Sequence>
<Sequence id="cancelSeq">
<Attempt action="{CheckForChanges}" guard="{NotQuitting}" fail="{ShowAdvice}"/>
<Attempt action="{ConfirmWithUser}"/>
<Execute action="{RevertData}"/>
</Sequence>
</children>
</Flow>
public function defineSaveFlow()
{
var processSaveRequest:CommandFlow = new CommandFlow();
processSaveRequest
.addGuard(ApplicationIsNotQuitting)
.execute(ValidateChanges);
processSaveRequest
.from(ValidateChanges)
.afterEvent(ValidationEvent.VALIDATED)
.execute(OfferConfirmationDialog);
.afterEvent(ValidationEvent.NOT_VALIDATED)
.execute(ShowError);
.exit();
processSaveRequest
.from(OfferConfirmationDialog)
.afterEvent(ConfirmationEvent.CANCELLED)
.exit();
.afterEvent(ConfirmationEvent.CONFIRMED)
.executeAll([BlockQuitting, SaveData]);
processSaveRequest
.from(SaveData)
.afterEvent(DataServiceEvent.COMPLETED)
.executeAll([StoreSavedData, UnblockQuitting])
.exit();
.afterEvent(DataServiceEvent.ERRORED)
.executeAll([ProcessSaveError, UnblockQuitting])
.exit();
commandMap.mapFlow(processSaveRequest, ScreenActionEvent.SAVE_REQUESTED);
}
public function defineDeleteFlow()
{
var processDeleteRequest:CommandFlow = new CommandFlow();
processDeleteRequest
.addGuard(ApplicationIsNotQuitting)
.execute(ValidateDelete);
processDeleteRequest
.from(ValidateDelete)
.afterEvent(ValidationEvent.VALIDATED)
.execute(OfferConfirmationDialog);
.afterEvent(ValidationEvent.NOT_VALIDATED)
.execute(ShowError);
.exit();
processDeleteRequest
.from(OfferConfirmationDialog)
.afterEvent(ConfirmationEvent.CANCELLED)
.exit();
.afterEvent(ConfirmationEvent.CONFIRMED)
.executeAll([BlockQuitting, DeleteData]);
processDeleteRequest
.from(DeleteData)
.afterEvent(DataServiceEvent.COMPLETED)
.executeAll([UpdatedDeletedData, UnblockQuitting])
.exit();
.afterEvent(DataServiceEvent.ERRORED)
.executeAll([ProcessDeletionError, UnblockQuitting])
.exit();
commandMap.mapFlow(processDeleteRequest, ScreenActionEvent.DELETE_REQUESTED);
}
public function defineCancelFlow()
{
var processCancelRequest:CommandFlow = new CommandFlow();
processCancelRequest
.addGuard(ApplicationIsNotQuitting)
.execute(CheckForChanges);
processCancelRequest
.from(CheckForChanges)
.afterEvent(ComparatorEvent.CHANGES_FOUND)
.execute(OfferConfirmationDialog);
.afterEvent(ComparatorEvent.NO_CHANGES_FOUND)
.execute(ShowAdvice);
.exit();
processCancelRequest
.from(OfferConfirmationDialog)
.afterEvent(ConfirmationEvent.CANCELLED)
.exit();
.afterEvent(ConfirmationEvent.CONFIRMED)
.execute(RevertData)
.exit();
commandMap.mapFlow(processCancelRequest, ScreenActionEvent.CANCEL_REQUESTED);
}
@Stray
Copy link

Stray commented Nov 1, 2011

But - I should stress that Till is doing CommandMap stuff at the moment, I may be behind.

@neilmanuell
Copy link

I see...
I shall just have to wait.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment