Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Section
Column
width15px

Column
Wiki Markup

h4. A Lightning Look at Configuration

Configuring Swiz in your Flex or AIR application is very straightforward: declare {{Swiz}}, define the {{beanProviders}} and {{config}} properties, and optionally define one or more {{loggingTargets}} to view debugging messages. Here is an example:

{html}<script src="http://gist.github.com/383055.js?file=quickswiz_main.xml"></script>{html}
//\\

Non-visual components that you want Swiz to manage are defined in a {{BeanProvider}} tag. Any beans that you define within the {{BeanProvider}} are processed by Swiz for dependency injection and the creation of event mediators. In the following example, a {{UserService}} and a {{UserController}} are created: 
{html}<script src="http://gist.github.com/383055.js?file=quickswiz_beans.xml"></script>{html}

h4. The "Big Three": Dependency Injection, Event Handling, and Server Interaction

The three most commonly used features of Swiz are its dependency injection capabilities, its event handling features, and its server interaction utilities. Let's look at how each of these work.

h4. Adding Dependency Injection

Dependencies are injected by using {{\[Inject\]}} metadata. In this example, the {{UserService}} is injected into the {{UserController}}:

{html}<script src="http://gist.github.com/383055.js?file=quickswiz_usercontroller.java"></script>{html}
//\\

In addition to injecting a bean, you can inject individual bean properties. In this example, the {{currentUser}} property of the {{UserController}} is injected into a {{UserForm}} visual component. Note that it is not necessary for the {{UserForm}} to be declared as a bean in the {{BeanProviders}} tag. When visual components are added to the display list, Swiz automatically inspects them and processes any metadata tags that are found. 

{html}<script src="http://gist.github.com/383055.js?file=quickswiz_userform.mxml"></script>{html}

h4. Dispatching and Handling Events
{html}<script src="http://gist.github.com/383055.js?file=quickswiz_userform.mxml"></script>{html}
{html}<script src="http://gist.github.com/383055.js?file=quickswiz_userevent.java"></script>{html}
{html}<script src="http://gist.github.com/383055.js?file=quickswiz_usercontroller.java"></script>{html}

h4. Talking to the Server
{html}<script src="http://gist.github.com/383055.js?file=quickswiz_usercontroller.java"></script>{html}
{html}<script src="http://gist.github.com/383055.js?file=quickswiz_userservice.java"></script>{html}

h4. There's More Where That Came From

Column
width15%