I was asked today at work if I could do a quick walkthrough of the Swiz framework via Connect. In the end, we decided that I should recorded a screencast that anyone can view, available below.
Swiz is a darn-near magical framework for Flex that gives you the benefits of dependency injection, event-driven development, and separation of concerns without the boilerplate or heavy reliance on base class functionality present in other frameworks. Going further, it's darn simple to learn: 20 minutes of example and a quick skim of the feature list should be all you need to begin being effective.
If there's two things to get from the following video, they are:
- Swiz manages your dependencies in the POJO-vein of Spring/ColdSpring
- Swiz lets you write plain, non-framework AS3 code that's wired together with terse metadata
Swiz in 15 minutes from Joe Rinehart on Vimeo.
Comment 1 written by Sam Farmer on 21 October 2009, at 4:00 PM
Comment 2 written by Raymond Camden on 21 October 2009, at 5:07 PM
Comment 3 written by John Gag on 22 October 2009, at 11:20 AM
Comment 4 written by Brian Kotek on 22 October 2009, at 12:46 PM
If you're OK with extending AbstractController, you can leverage the executeServiceCall and Swiz's DynamicResponder, which would eliminate all of the responder code. As a bonus, when you use executeServiceCall, you get the ability to create a global service failure handler for free. Yes, it's coupling to Swiz, but you're already couple to Swiz just by using Swiz to dispatch events. The controller is really the only place where there is direct coupling to Swiz.
You probably already know, but you can avoid the need to use the bean IDs if you just Autowire by type. (I hate having to look that up heh). It handles interfaces and inheritance too!
Finally, you can get runtime (app startup, actually) type checking of mediated events by setting strict to true in the SwizConfig and using static event types like "MyEvent.DO_SOMETHING" as the event name in the [Mediate] metadata. As a nice bonus, Swiz will automatically generate the code for the event in the debug output if it can't find it, so it can just be copied and pasted into an Event class. Takes much of the pain out of writing your Event classes by offering a little jump start on them. :-)
Comment 5 written by Henry Ho on 22 October 2009, at 2:56 PM
I guess I don't know enough Flex... time to pick up a book.
Comment 6 written by Joe Rinehart on 23 October 2009, at 5:52 AM
@Brian,
Yep, there's a ton of things you and I both know Swiz can do that I didn't do. I needed to focus on concepts....all the details give me fodder for more videos.
Personally, extending AbstractController just to do executeServiceCall() isn't worth it for me...I'm using a class I've written called RPCMediator to handle this kind of stuff for me. You can probably guess what it does from its constructor:
RPCMediator(resultEvent : String, resultEventProperty : String, faultEvent : String = null, eventArgs : Object = null, result:Function = null, fault:Function = null)
Comment 7 written by johans on 26 October 2009, at 8:11 PM
Comment 8 written by shaun on 10 November 2009, at 1:42 AM
http://shaun.boyblack.co.za/blog/2009/11/10/robotl...
Comment 9 written by Adobe Flex Tutorial on 22 November 2009, at 8:58 AM
i shared this very interesting video on my blog (french):
http://www.flex-tutorial.fr/2009/11/22/swiz-tutorial-video-introduction-a-swiz-en-20-minutes/" target="_blank">http://www.flex-tutorial.fr/2009/11/22/swiz-tutori...
Really good job on that one, and excellent comments
Fabien
http://www.flex-tutorial.fr
Comment 10 written by johans on 7 December 2009, at 8:39 PM
Comment 11 written by RMan on 15 December 2009, at 7:04 AM
[Mediate(event="dataRequestGetUser", properties="id")]
public function GetUser(id:int):void
Now, how do I dispatch event from FormController to pass user id I want to load? What if I want to send user object to server?
<mx:Button label="Refresh" click="dispatchEvent(new Event(DataController.DATA_REQUEST_GET_USER, true))" />
Comment 12 written by Brian Kotek on 30 December 2009, at 11:47 AM
@RMan: If you're not sure how to create an event that contains a property, or how to communicate with the server, I think you probably want to step back and go through the Flex documentation, as this is all fundamental stuff that really has nothing to do with Swiz.
[Add Comment] [Subscribe to Comments]