foomonger's blog

Tips and Musings on Software Development, Flash, and Flex

Swiz, Signals, and [MediateSignal]

with 2 comments

Joel Hooks created this RobotLegs/Signals demo. Ben Clinkinbeard then created this Swiz-version of Joel's demo. I then took Ben's demo and Swiz-ified it even more by using a custom [MediateSignal] processor. Here's the source.

[MediateSignal] is the Signal equivalent of [Mediate]. Here's an example:

[MediateSignal("galleryUpdatedSignal")]
public function galleryUpdated(gallery:Gallery):void

[MediateSignal] takes a Signal Bean name or type and adds the decorated method to the Signal (see GalleryThumbnailsPresentationModel for examples).

This is what I changed from Ben's demo:

  • Created the MediateSignalProcessor
  • Added [MediateSignal] metadata to the Signal listeners
  • Made the Signal listeners public
  • Named the Signal Beans
  • Removed [PostConstruct] methods that added the Signal listeners
  • Removed injected Signals that weren't being using to dispatch

[MediateSignal] makes using Signals in Swiz very parallel to using Events (especially if you define the Event dispatcher as a Bean and inject it by name). And just like Events, you only need to [Inject] the Signals into Beans who are dispatching Signals. I was pretty excited to create my first custom processor and play with Signals for the first time. Let me know what you think!

Disclaimer: I set up MediateSignalProcessor to also handle DeluxeSignals and remove listeners, though to be honest I didn't test those.

* Update: I've posted the processor on Google Code and it contains unit tests (including DeluxeSignals and removing listeners).

** Update: I've created a bare-bones example application: SWF and Source.

Share

Written by Sam Ahn

February 26th, 2010 at 11:37 pm

Posted in flex

Tagged with , , ,

2 Responses to 'Swiz, Signals, and [MediateSignal]'

Subscribe to comments with RSS or TrackBack to 'Swiz, Signals, and [MediateSignal]'.

  1. I’ll be providing more formal packaging of the MediateSignalProcessor that will work with the latest version of Swiz and Signals this weekend. Unit tests and all. Stay tuned.

    Sam Ahn

    27 Feb 10 at 6:59 PM

  2. I’ve written a library project for MediateSignalProcessor, created unit tests, and put it all up on Google Code here:
    http://code.google.com/p/foomonger-swizframework/

    Any future Swiz-related code will get tossed up there.

    The project also uses the latest version of Swiz so it should work with the upcoming beta release.

    I’ve also updated the source on this post. Nothing much to see since all I did was update the Swiz SWC and replaced the MediateSignalProcessor file with a SWC.

    Sam Ahn

    28 Feb 10 at 3:38 AM

Leave a Reply