Swiz 0.6 Released

Chris just released a new version of Swiz with some really great additions and improvements. We now also own the domain swizframework.org which forwards to the Google code homepage.

This release makes Swiz faster, more flexible and even easier to use:

  • Support for mediating bubbled event
  • Added view attribute in Mediate tag
  • Autowire views with view attribute in Autowire tag
  • Ignoring view classes with underscore for performance optimization
  • Added viewPackages for performance optimization
  • Added eventPackages for shorter notation in strict mode
  • SwizConfig for Swiz MXML declaration
  • Generic fault handler for executeServiceCall
  • Autowire bean properties with new property attribute
  • Prototype supports class reference and constructor arguments

Swiz got a new member Ben Clinkinbeard who contributed some really cool stuff which makes mediating events more flexible and removed the Swiz dependency from the view because they can now bubble and lot’s of other stuff. Awesome to have Ben on board!

So here a quick overview for each new feature/improvement:

Support for mediating bubbled event

Events don’t have to be dispatched with the central event dispatcher anymore. So when you have a view instead of:

Swiz.dispatchEvent(new FooEvent(FooEvent.CHANGE))

you can do:

dispatchEvent(new FooEvent(FooEvent.CHANGE))

When you want to use this approach you have to

  • enable the feature with Swiz.setMediateBubbledEvents(true) or via SwizConfig
  • set the bubble flag of the event to “true”
  • override clone method of the event

So the view has no Swiz import statement anymore and in fact doesn’t know anything about Swiz except to autowire models.

Added view attribute in Mediate tag

A dynamic mediator can now listen for view specific events. In the following example the dynamic mediator only listens for events dispatches by the view class “MyView”:

[Mediate(event="SomEvent.FOO", view="MyView")]

This is also extremely helpful to code more generic itemRenderers.

Autowire views with view attribute in Autowire tag

You can now autowire views into any bean with:

[Autowire(view="true")]
public function set myView(view:MyView):void
{...}

The setter is invoked when the view is added to the stage and has fired its creationComplete event so you can access all members of the view which in MXML are all public scope.
For more details and an example read my post here.

Ignoring view classes with underscore for performance optimization

This is an internal performance optimization where you as a developer don’t have to change anything except you have view classes with an underscore in the classname.
In Swiz 0.6 view classes with “_” are ignored for dependency injection because these are internal classes like skin classes, cursors or internal non-custom item renderers. Because these kind of classes won’t contain any metadata we can safely ignore them which improves the runtime performance significantly.

Added viewPackages for performance optimization

For further optimization beyond already ignoring underscore classes you can now define one or multiple view packages. If you set this property only views in these packages will get autowired.
You can set the viewPackage with

Swiz.addViewPackage("com.domain.project.view")

or with the new SwizConfig.

Added eventPackages for shorter notation in strict mode

When you are using Swiz in strict mode you can now define eventPackages to have a shorter notation of the event. I already blogged about this feature here.

SwizConfig for Swiz MXML declaration

Instead of adding an event listener for the Application/WindowedApplication preInitialize event and the calling Swiz.loadBeans besides configuring Swiz you can now use the new SwizConfig class in MXML. The markup for an AIR app then looks like this:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 
	<mx:Script>
		<![CDATA[
			import mx.rpc.events.FaultEvent;
			import mx.logging.LogEventLevel;
 
			private function genericFault(fe:FaultEvent):void
			{
				// TODO handle fault
			}
 
		]]>
	</mx:Script>
 
	<mx:TraceTarget fieldSeparator="->" includeLevel="true" includeCategory="true" includeTime="true" />
 
	<swizframework:SwizConfig xmlns:swizframework="org.swizframework.*"
		strict="true"
		mediateBubbledEvents="true"
		eventPackages="example.event"
		viewPackages="example.view"
		beanLoaders="{[Beans]}"
		serviceCallFaultHandler="{genericFault}"
		logEventLevel="{LogEventLevel.WARN}"
		/>
 
	<view:SwizConfigTestView xmlns:view="example.view.*" width="100%" height="100%" />
 
</mx:WindowedApplication>

The SwizConfig itself will listen for the preInitialize event of the application and configure Swiz.

Generic fault handler for executeServiceCall

When you use Swiz.executeServiceCall or subclass AbstractController and call executeService call you can leave out the fault handler. When a fault comes up Swiz currently shows an Alert window with the fault details. You can override this like in the SwizConfig example above.

Autowire bean properties with new property attribute

You can now autowire bean members instead of the bean itself. So instead of:

[Bindable][Autowire]
public var someModel:SomeModel;
 
<mx:List dataProvider="{someModel.someList}" />

you can use:

[Bindable][Autowire(bean="someModel", property="someList")]
public var someList:ICollectionView;
 
<mx:List dataProvider="{someList}" />

Prototype supports class reference and constructor arguments

Prototype (see old post here) now support constructor arguments and you can declare a class reference instead of the full qualified class name.
Example:

<factory:Prototype xmlns:factory="org.swizframework.factory.*"
	classReference="{SomeClass}" constructorArguments="{['foo', 'bar']}" />

There will come a lot of new blog posts regarding each new feature soon but I hope this has given an overview about what’s new in 0.6. Besides that we try to add more documentation and example projects.

15 comments to Swiz 0.6 Released