My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
ReactionsNewApproach  
New Reactions approach
Featured
Updated Jul 14, 2010 by rafael.s...@gmail.com


Introduction

Starting 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 ).

Requirements

This feature needs Fabrication version 0.7.1 or above.

Usage Scenario

Consider 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

  1. To use new Registration mechanism you don't need to declare public getter to viewComponent child if this child is accessible outside this component. You have to remember about CamelCase naming convention.
  2. You can use capture phase by declaring method as: trap<ComponentName>$<EventName>
  3. All others details are the same as in standard reactions ( removing, constant style event names etc. )

Examples

  1. New reactions example Demo Source
Comment by piotr.wi...@gmail.com, Aug 12, 2010

Is there any possibility to add reaction to Form from example (viewComponent) with the new approach syntax?

Comment by atendime...@gmail.com, Feb 11, 2011

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.

Comment by atendime...@gmail.com, Feb 11, 2011

Piotr.wi: sure it´s!

e.g.: getter for viewComponent is app for example

public function ReactToApp?$ApplicationComplete?(event:BeSureUsingAdequateKindOfEventIfNotReactionFails?):void{}


Sign in to add a comment
Powered by Google Project Hosting