Cairngorm is a framework which facilitates to write well structured flex code with MVC architecture. Its Front controller, Model Locator, command and delegate patterns are the main components of the framework. I will try to explain how it works with a simple example application of user search.
- App boots up, shows first state
- user types in some keywords, clicks the Search button
- this fires the doSearch event handler
- the doSearch handler creates a CairngormEvent, and dispatches it
- the Controller has mapped that type of event to a Command, and thus it runs the command, passing it the event
- the Command looks at the event type in the execute function and
decides what to run, in this case, searchBooks, passing the event’s
data to the function - search books creates the Business Delegate, and calls its method
- the Delegate gets the WebService from the ServiceLocator, fires off the WebService, and waits for a response
- if the response is successful, it parses the E4X XML via a Factory to a list of Book ValueObjects
- finally, it calls the responder’s onResult function
- Since the Command is the Responder, he gets the data, and sets it to the ModelLocator and updates the applications state
- The View’s are bound to the state variable and book list in the ModelLocator, so they immediately have their bindings fire
- This causes the main app to change state, and show the results DataGrid
- The results DataGrid is bound to the books list in the ModelLocator, and shows the results.
No comments:
Post a Comment