Cairngorm internal event flow

This has been a big anxiety in my mind to know about the event flow mechanism than runs internally inside the cairngorm until I could look in to the source code of it. Here are my observations in short:

Steps a programmer does while utilizing the architecture:

1. Create a command class and write down the execution details.

2. Register command inside the front controller class.

3. Instantiate front controller inside view class

4. Dispatch custom event which extends the CairngormEvent class by the help of the CairngormEventDispatcher.getInstance().dispatchEvent method.

And everything goes fine. You are able to catch the event and do whatever inside the execute method in command class. Now look at the steps that Cairngorm does for you. (Note: work performed by cairngorm is highlighted)

1Instantiate front controller inside view class.   When ever a controller class is instantiated an event is is registered to some command by the method addCommand. This method checks if a same command is already registered before. If it’s a new command  it does two things: a. it keeps the command class reference in a dictionary object with comamndName as the key.  b. It takes an instance of the CairngormEventDispatcher class and adds an event listener for the commandname and handles this event by executeCommand method. 

2. Dispatch custom event which extends the CairngormEvent class by the help of the CairngormEventDispatcher.getInstance().dispatchEvent method. CairngormEventDispatcher dispatches the Caingorm event. Which alternately dispatches the comand name event, and  being listened by the front controller class , because it has an event listener for this. Now this event is handled with executeCommand event handler. The executeCommand event handler does two things: a. Finds the command class being listed inside the dictionary object in front controller by the command name key. b. As command class has already implemented IComamnd the event handler keeps the command object in a ICommand object and calls the execute event.  And the command gets executed.

This entry was posted in Architectures, Design Patterns, Flex 3.0, Flex 4. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>