Placing view logic

jakub.gondek's Avatar

jakub.gondek

16 Nov, 2012 12:39 PM

Hi all,

I'm preety new to Robotlegs, in fact I haven't written a single project involving the framework. Since my projects grow and get unmanageable I decided to get into Robotlegs, but I have a question.

Most of my views are Sprites placed on stage in Flash Professional, exported as SWC, and instantiated in application by creating a single "ApplicationAssets" Sprite. Than concrete Sprites are passed to "wrappers" that add specific view logic, but are not display objects.

The question is: where to put instantiatioin of those "wrappers"?

  1. 1 Posted by matt on 16 Nov, 2012 01:04 PM

    matt's Avatar

    the "wrappers that add specific view logic" sound a lot like mediators to me - if mapped to specific DisplayObject classes in your application these mediators would then be automatically created with a reference to the DisplayObject in question when you add it to the stage.

  2. 2 Posted by jakub.gondek on 16 Nov, 2012 01:18 PM

    jakub.gondek's Avatar

    In ActionScript Developer’s Guide to Robotlegs by Joel Hooks and Stray (Lindsey Fallow) on page 61 paragraph title says "Avoid logic in your Mediators". Removing logic from those "wrappers" is impossible, so how to treat them then?

  3. 3 Posted by matt on 16 Nov, 2012 03:58 PM

    matt's Avatar

    logic specific to the view in question would take place in the mediator, more generic application logic can be moved out into commands and events/signals that your mediators interact with and respond to - depends on the size and complexity of your application really. It's a matter of opinion but personally i don't have a problem with mediators handling logic in a smaller application - keeps things quick and simple, chunks of logic can be moved out into commands if and when it becomes necessary to trigger the logic via events from other areas of the app - your mediators then become simple conduits to channel events and relevant data from the application logic to your views.

  4. Support Staff 4 Posted by Ondina D.F. on 16 Nov, 2012 04:16 PM

    Ondina D.F.'s Avatar

    Adding to matt’s answer:

    Are those „wrappers“ some kind of a factory?
    See this discussion
    http://knowledge.robotlegs.org/discussions/questions/474-no-subject

  5. Support Staff 5 Posted by Ondina D.F. on 16 Nov, 2012 04:38 PM

    Ondina D.F.'s Avatar

    Or, if you need a "wrapper“ inside your views, you can pass it to the views through their mediators.
    If your „wrappers“ are neither mediators, nor factories, nor helpers, what are they?
    Could you say more about the roles of those „wrappers“ ?

  6. 6 Posted by jakub.gondek on 16 Nov, 2012 08:24 PM

    jakub.gondek's Avatar

    Those "wrappers" connect graphic assets with state machine and some helper methods.

  7. Support Staff 7 Posted by Ondina D.F. on 20 Nov, 2012 11:18 AM

    Ondina D.F.'s Avatar

    Hey Jakub,

    Well, that’s a lot of information ;-)

    If your “wrapper” has more than one responsibility, then I’m pretty sure, it should be split into more classes, each one with its own, single responsibility:
    a Service (with or without a factory) +Model + Commands +Mediator.
    What you call “view logic” could be in fact a Mediator, or a Command or even a Model. It’s really hard to say.
    Your use case is too generic= many different, valid solutions.

    Loading external resources is, usually, the responsibility of a Server class.

    I’m not going to go into details about the roles of the robotlegs actors, since you said you’ve read the rl book already, and probably the Best Practices as well.
    I’m not sure how many examples you’ve seen already, but it would be a good idea to look at as many examples/demos as possible (see the long list under Resources and Examples - Robotlegs 1).
    Also, there are many discussions on the topic, use keywords like “loading assets”, “assets”, “bootstrapping”.

    Regarding statemachine and bootstrapping, you can take a look at

    Ondina

  8. 8 Posted by jakub.gondek on 20 Nov, 2012 12:01 PM

    jakub.gondek's Avatar

    Hi,

    I was going to post some API exposed by "wrappers", but this is my spare time research, and haven't much spare time last couple of days. Ill do it today - because maybe I'm using the wrong word saying "wrapper", and hopfuly it will clarify a bit.

    My approach to state machines is slightly diffrent than these two so I'll take a look at them.

    The Creynders’ Bootstrapping project seems very interesting.

  9. Support Staff 9 Posted by Ondina D.F. on 20 Nov, 2012 01:10 PM

    Ondina D.F.'s Avatar

    ok:)

  10. 10 Posted by jakub.gondek on 20 Nov, 2012 01:34 PM

    jakub.gondek's Avatar

    This is the API provided by "wrappers".

  11. Support Staff 11 Posted by Ondina D.F. on 20 Nov, 2012 02:53 PM

    Ondina D.F.'s Avatar

    Cool, I'll take a look at it.

  12. Support Staff 12 Posted by Ondina D.F. on 20 Nov, 2012 03:16 PM

    Ondina D.F.'s Avatar

    To me, it looks like you could use the wrappers as a BaseView or a View interface.
    The states, in StatefulWrapper, seem to be view-states, thus it is logic belonging to the view. Neil’s statemachine is for application-states. Transitions, view states, mouse events handlers, enabled, selected, or hide/show are all view logic.

    This could be of use, if you’d want to mediate Views as interfaces with rl1:
    https://github.com/piercer/robotlegs-extensions-ViewInterfaceMediat...

    but it seems to have some issues when combined with the newest versions of rl1 and swiftsuspenders.

  13. Support Staff 13 Posted by Ondina D.F. on 20 Nov, 2012 04:18 PM

    Ondina D.F.'s Avatar
  14. Support Staff 14 Posted by Ondina D.F. on 20 Nov, 2012 04:26 PM

    Ondina D.F.'s Avatar

    As far as I remember, Stray used a view factory in the mosaictool example: https://github.com/Stray/robotlegs-examples-OreillyBook

  15. Support Staff 15 Posted by Ondina D.F. on 22 Nov, 2012 04:30 PM

    Ondina D.F.'s Avatar

    Jakub, if you want to respond, you can re-open the discussion. I have to close it because of the spam.

  16. Ondina D.F. closed this discussion on 22 Nov, 2012 04:30 PM.

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

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac