|
ReactionsNewApproach
New Reactions approach
Featured IntroductionStarting from verion 0.7.1 you can use advanced reaction registration mechanism. From now you can use: reactTo<ComponentName>$<EventName> syntax ( be aware of dollar sign between component and event name ). RequirementsThis feature needs Fabrication version 0.7.1 or above. Usage ScenarioConsider the typical anatomy of a PureMVC Mediator class for an mxml view component show below. MyForm.mxml <mx:Form> <mx:TextInput id="emailInput" /> <mx:Button id="submitButton" label="Submit Button"/> </mx:Form> FormMediator.as public class FormMediator extends FlexMediator {
static public const NAME:String = "FormMediator";
public function FormMediator(viewComponent:Object) {
super(NAME, viewComponent);
}
/* not needed anymore
public function get submitButton():Button {
return viewComponent.submitButton as Button;
}
*/
public function onRegister():void {
submitButton.addEventListener(MouseEvent.CLICK, submitButtonClicked);
}
private function submitButtonClicked(event:MouseEvent):void {
// submit form
}
}
Instead of subscribing to the click event you just add a click handler with the reactTo syntax. public function reactToSubmitButton$Click(event:MouseEvent):void {
// submit form
}Implementation Details
Examples | |
► Sign in to add a comment
Is there any possibility to add reaction to Form from example (viewComponent) with the new approach syntax?
Just for generate some discussion... resolve(mediator) doesn´t fire onremove event? interestingly registermediator (without resolve) works the reactions if registered before instantianting new "group"... but no other kind of component (solution registermediator after adding the component)...
and just for curiosity... i´ve needed in a situation... two different mediators and same view... it´s prohibited? can cause conflits/bugs/performance? e.g.: applicationView registered with applicationMediator and registered mdiManager too. (seems no problem.. but im asking for precaution)
Thanks. Vander.
Piotr.wi: sure it´s!
e.g.: getter for viewComponent is app for example
public function ReactToApp?$ApplicationComplete?(event:BeSureUsingAdequateKindOfEventIfNotReactionFails?):void{}