Question

I have a Command that executes a service call. In the result handler, I am doing some logic based off the result data. If the logic meets specific criteria, I am displaying a confirmation popup. If the user clicks the continue button in the confirmation popup, I have a method that gets called, which dispatches a Parsley event. That Parsley event is not being caught. However, if I dispatch the Parsley event from inside the result method, it is being caught. Any idea why the event is not being caught when dispatching it from outside the result method?

For example...

[MessageDispatcher]
[Bindable]
public var dispatcher:Function;

I execute some service call from inside the command:

public function execute(event:SomeEvent):AsyncToken
{
return service.callService(event.type, false);
}

I now have a result handler like this:

public function result(data:Object):void
{
if (add some logic here based off data)
AlertHelper.showContinueQuestion(onSelection, "Are you sure you want to continue?");
}

If the user clicks the Continue button on the confirmation popup, it calls the onSelection method:

private function onSelection():void
{
dispatcher(new SomeEvent(SomeEvent.UPLOAD));
}

That Parsley event, SomeEvent, is not being caught. However, if I dispatch that event after the if statement, it is being caught and works fine. Any idea why it is not being caught when dispatched from outside of the result handler? I tried in other commands too, and it does the same thing.

Was it helpful?

Solution

Found this on the Spicefactory site, works as designed. I ended up updating a flag in the Model, versus dispatching an event. I then have a BindSetter listening for changes to that flag in the model. When the flag is set to true, the Parsley event is dispatched.

Command Object Lifecycle

Apart from grouping the executing method and the result handlers the DynamicCommand also introduces a special kind of lifecycle management for command objects. The creation of the object does not happen until a matching message is dispatched. It then becomes a container managed object just for the duration of the command execution. It will immediately be removed from the Context after the result or error handler have been invoked. But during its lifetime, it is a fully managed object, can have its dependencies injected, or even take part in messaging during the command execution. But that would be a rather rare case, most common usage scenario is probably the command object just receiving all the dependencies it needs to execute the command.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top