SwfSuspenders XML config field name values when using Signals

eco_bach's Avatar

eco_bach

10 Apr, 2010 09:21 PM via web

Hi
I'm a bit confused as to how my XML config file would change when switching over to Signals.

Right now the 3 framework Commands I am using are defined as follows. Both ViewChangedCommand and the InitViewCommand are mapped to custom events.








  1. 2 Posted by eco_bach on 10 Apr, 2010 09:24 PM

    eco_bach's Avatar

    Sorry, code didn't make it thru

    <type name='app.controller::StartupCommand'>
    <field name='dataService'/>
    </type>
    
    <type name='app.controller::ViewChangedCommand'>
    <field name='event'/>
    <field name='model'/>
    </type>
    
    <type name='app.controller::InitViewCommand'>
    <field name='model'/>
    </type>
    
  2. Support Staff 3 Posted by Shaun Smith on 15 Apr, 2010 09:59 AM

    Shaun Smith's Avatar

    By "switching over to Signals" do you mean using Signals to trigger Commands via Joel's SignalCommandMap?

  3. 4 Posted by eco_bach on 15 Apr, 2010 12:45 PM

    eco_bach's Avatar

    Yes, exactly. I'm extending SignalContext for my ApplicationContext class.

  4. Support Staff 5 Posted by Shaun Smith on 15 Apr, 2010 12:56 PM

    Shaun Smith's Avatar

    In that case, your Commands will be bound to Signals (not Events), and your XML fields will reference the Signal payload (not Event). I haven't played with the SignalCommandMap, so I'm not the best person to give advice. I assume you've read this:

    http://joelhooks.com/2010/02/14/robotlegs-as3-signals-and-the-signa...

    I do wonder why you are using the XML config in the first place. Are you compiling with the Flash IDE? Seems like a lot of effort to me!

  5. 6 Posted by Jim B on 15 Apr, 2010 01:27 PM

    Jim B's Avatar

    Shaun
    Yes I realize the advantages of compiling within FlexFlashbuilder, but most
    of my projects are design-asset heavy, with many design revisions.

    Perhaps I should consider exporting all my assets as swcs from Flash, then
    compile in FB, but this would just require one extra step every time there
    is a design revision.

    If you think I'm incorrect in still using Flash to compile considering the
    above, I'd appreciate your feedback.

    My goal is simply to get a working RobotLegs+SWFSuspenders+AS3Signals
    template I can extend and use on other projects.

  6. Support Staff 7 Posted by Shaun Smith on 15 Apr, 2010 01:45 PM

    Shaun Smith's Avatar

    There's no correct or incorrect way to do things: whatever works best for you. Personally, I do the export-to-swc technique for my assets as I spend more time compiling after code changes than compiling after design changes. But this may not be the case for you.

    I just find the XML config rather laborious. Another approach for Flash IDE compiled projects is to make use of constructor injection for your dependencies. Instead of doing this (which requires metadata):

    [Inject]
    public var dep:Dep;
    

    You could do this:

    protected var dep:Dep;
    
    public function MyClass( dep:Dep )
    {
        // store the dependency for later use
        this.dep = dep;
    }
    

    SwiftSuspenders doesn't need metadata to realize that it needs to perform constructor injection. The downside with this approach is that without metadata you can't have "named" injections. Also, it's more long winded than setter injection.

    If you do decide to try the constructor injection approach for use with the Flash IDE, be aware that you might still need to pass XML through to the SwiftSuspendersInjector - even if that XML object is empty - in order to set up the default injection points for the MVCS actors. I'm not 100% sure about this though, it might not be necessary.

  7. 8 Posted by Jim B on 15 Apr, 2010 02:24 PM

    Jim B's Avatar

    ok thanks, will try that, recall RPenner saying something similar in one of
    his posts

  8. 9 Posted by Jim B on 15 Apr, 2010 04:50 PM

    Jim B's Avatar

    Shaun
    Is there a working RL example you can refer me to using only constructor
    instead of property injection?

  9. Support Staff 10 Posted by Shaun Smith on 15 Apr, 2010 07:47 PM

    Shaun Smith's Avatar

    Aha, so, after trying to put together a quick demo, I notice that one still needs to define the injection points via XML for the default MVCS dependencies - I assumed that the default XML map would cover derived classes (descendants of Actor, Mediator etc) but that doesn't seem to be the case.. which is a total pain.

  10. 11 Posted by Jim B on 15 Apr, 2010 09:04 PM

    Jim B's Avatar

    ok, thanks for trying.
    So bottom line is, if I want to use Robotlegs and compile in the IDE, I
    cannot use AS3 signals

    The corollary being, if I want to use AS3Signals AND Robotlegs, I cannot
    compile using the IDE

  11. Support Staff 12 Posted by Shaun Smith on 16 Apr, 2010 01:00 PM

    Shaun Smith's Avatar

    Hi Jim,

    What I was getting at in my last post was that even if you use constructor injection for your actors you still need to provide a minimal XML map to cover the base injections - which isn't much of a time saver. It wasn't related to Signals at all.

    Signals, as far as I'm aware, should work just fine. You'd need to change your XML a little: instead of injecting events into your commands, the SignalCommandMap injects the payloads directly. So, for example:

    <type name='app.controller::ViewChangedCommand'>
    <field name='payload'/>
    <field name='model'/>
    </type>
    

    "payload" would be the injection point of the Signal's payload (rather than the Signal itself).

  12. Support Staff 13 Posted by Shaun Smith on 16 Apr, 2010 01:05 PM

    Shaun Smith's Avatar

    More specifically: if we take another look at Joel's post:

    http://joelhooks.com/2010/02/14/robotlegs-as3-signals-and-the-signa...

    We can see that AddFoodItemToOrder is a custom Signal that has FoodType as a payload. The corresponding Command AddFoodItemToOrderCommand gets injected with a FoodType (the payload, not a Signal). The XML mapping might look something like:

    <type name='app.controller::AddFoodItemToOrderCommand'>
    <field name='itemType'/>
    <field name='model'/>
    </type>
    

    Does that help at all?

  13. 14 Posted by Jim B on 17 Apr, 2010 05:49 PM

    Jim B's Avatar

    Thanks Shaun
    sorry for the delayed reply

    FINALLY have a working RL+ Swiftsuspenders + AS3 template working. Seems
    like magic when it finally works;)

    I think I stumbled a bit when I saw 'event in the XML config file, thinking
    it had to be 'typed' to Event, and therefore how would I type to 'Signal'?

    This is my modified XML config, all I needed to do was add entries for 2 new
    signal instances, inited, and updated.

    Question: Right now I add signal listeners in my mediator onRegister method.
    I see Joel makes use of [postconstruct] with a method to add signal
    listeners in an example.
    Could I also use postconstruct in my mediators for adding signal listeners?

     <types>
     <type name='app.model::DataService'>
    <field name='model'/>
     <field name='inited'/>
    </type>
    <type name='app.model::SiteModel'>
     <field name='updated'/>
    </type>

     <type name='app.view::BaseMediator'>
    <field name='view'/>
     <field name='siteModel'/>
    <field name='updated'/>
     </type>

    <type name='app.controller::StartupCommand'>
     <field name='dataService'/>
    </type>
     <type name='app.controller::InitViewCommand'>
    <field name='model'/>
     </type>

    <type name='app.controller::ViewChangedCommand'>
     <field name='event'/>
    <field name='model'/>
     </type>
    </types>;

  14. 15 Posted by Jos Yule on 18 Apr, 2010 02:58 PM

    Jos Yule's Avatar

    I should also add, that i've developed an AIR application to create the XML config file for you - you just point it at the root of your class file structure, and it recurses though the files, generating the XML.

    I'm in the process of cleaning it up and releasing it (again), if you are interested.

    jos

  15. 16 Posted by Jim B on 18 Apr, 2010 03:02 PM

    Jim B's Avatar

    sure, sounds awesome!

  16. Support Staff 17 Posted by Shaun Smith on 11 May, 2010 03:44 PM

    Shaun Smith's Avatar

    Hang on a sec.. It seem that compiling with Flash CS3/4/5 might work after all. In your Flash project, under Publish Settings:

    Set "Export SWC" to true
    Add Robotlegs and SwiftSuspenders source to your Source Path
    Compile

    I just tested it with a simple project and it worked! Can anyone else confirm this?

  17. Shaun Smith closed this discussion on 20 Jun, 2010 04:16 PM.

Comments are currently closed for this discussion. You can start a new one.