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.


Awesome! I just started refactoring a project away from Cairngorm and you just saved me sooooo much time. Thanks guys! Keep up the excellent work!
Where is org.swizframework.delegate.AbstractDelegate?
Did I miss something in the docs? Project doesn’t compile with the new swc.
I just checked out the source and it appears the delegate package is missing from the swc (or eclipse is playing games with the package
Linked to source – all is good. You might check the swc build… Kudos for all the hard work
[...] Sonke Rohde published great post explaining all the new features: http://soenkerohde.com/2009/05/swiz-06-released/ [...]
Hey Chris, you should not use AbstractDelegate, we removed it and it does not give you anything
Thanks Chris, I’ll gut it… that much less to maintain
AbstractDelegate is used in the sample application, so should that be update?
@Lawrence yes, the docs will be updated in the future. However, be sure to use 0.6.2: http://soenkerohde.com/2009/06/swiz-062-with-flex-4-support/
>> @Lawrence yes, the docs will be updated in the future.
Any clue when ‘the future’ might be?
I am currently on vacation so expect more changes Sep/Oct
It’s the Future already…
Can we get the example updated? It sucks when you’re trying to chop your teeth on something. And the “examples” don’t work out of the box.
Getting the following is NOT fun….
***
Severity and Description Path Resource Location Creation Time Id
1017: The definition of base class AbstractDelegate was not found. swiz-tests-flex/src/foo/delegates HelloDelegate.as line 8 1258401612859 2
The example is outdated so please look at the examples here: http://swizframework.org/examples/
Sorry for any inconvenience.
I’ve also tripped up on trying to run that example with AbstractDelegate.
As of today, two of the ‘new’ examples at http://swizframework.org/examples/ have broken links/servers down. Brian’s pages look really good, but the code doesn’t run until it has become quite sophisticated.
What would be really useful is an absolute beginners ‘Hello World’ example, giving the simplest possible example of Autowire and Mediate
I’ve filed an issue (issue 74) on swiz regarding property autowiring timing with dynamic mediators.
http://code.google.com/p/swizframework/issues/detail?id=74