How are Commands Triggered in MVCS Implementation?
Commands are triggered by framework events dispatched by Mediators, Services, Models, and other Commands. Typically the Event that triggered the Command is injected into the Command giving the Command access to the Event’s properties/payload:
public class MyCommand extends Command { [Inject] public var event:MyCustomEvent; [Inject] public var model:MyModel; override public function execute():void { model.updateData( event.myCustomEventPayload ) } }
When the mapped command is instantiated in response to a framework event, all of the dependencies that have been mapped and marked with the [Inject] metadata tag are injected into the Command. In addition, the event instance that triggered the Command is also injected. After these dependencies have been supplied, the executed method is called automatically and the Command’s work is performed. It is not necessary, and should never be done, to call the execute() method directly. This is the framework implementation’s job.