Ok perfect J  You can accomplish this very cleanly without having to know about any views, buttons or UI elements, and still do it with the ModelLocator and commands (if you choose).  I prefer to stay away from viewlocators as well, I use binding strategies for all the view logic, and I have only found a couple of situations where it didn’t work good (mainly setting verticalScrollPositions and selectedItems on lists).  What I usually do in the situation of the buttons being disabled and enabled is add a boolean field to the ModelLocator called loggedIn or something of that nature, bind the UIComponent’s enabled field to that, then set that from within the commands.  For the states issue, I usually define the states within a state factory or the MXML itself, depending on how complicated the states are and if I need dynamic states.  Then I create a state model that all my views can bind their currentState to.  Then a static list of all the available states per view (that part can be a bit tedious) and then I can change the states of views from anywhere in the application.  Just make sure that you bind the name of your state to the static variables you create on the model, that way everything is consistent.

 

The way you are thinking would work great too.  It would allow you to encapsulate all the code within the MXML files and make it a bit easier for someone to jump into.  The only thing that steered me away from that approach was forking out some of the logic out of the commands and back into the views.  I am a bit of a purist when it comes to using frameworks).  It’s just what I prefer.  But do what works best for you.  I just wanted to make sure you knew it was possible to accomplish the same thing within the cairngorm framework.

 

Dustin Mercer

 


From: [email protected] [mailto:[email protected]] On Behalf Of Derrick Grigg
Sent: Wednesday, October 25, 2006 2:06 PM
To: [email protected]
Subject: [flexcoders] Re: Cairngorm, dispatching application events and managing states

 

The biggest things I need to do are update/change the state of views
within the application. For instance, when a user has logged in
certain buttons get enabled, or certain panels become visible that
would not be so when the user is logged out.

I was thinking along the lines of using Commands, but I don't think
Commands should be concerned about the specific details (ie text
fields, buttons, etc) of a view. Using Commands would also entail
having to register all my views with a locator that would be used to
allow the Commands to find Views. Seems like a huge pain.

To me it seems much cleaner to allow the views to listen for certain
events (likely dispatched from a Manager) and then respond accordingly.

Derrick

--- In [EMAIL PROTECTED]ups.com, "Dustin Mercer" <dustin.mercer@...>
wrote:
>
> Out of curiosity, what is it you want to do when the login happens. I
> have only found a few things that were difficult to do from within a
> command. If you can tell me what you want to do, I can tell you what I
> have done in the past and how I accomplished it from within a command.
> In my Cairngorm trials, I had come to some of the same thinking as you
> described here, but I found that there were ways to accomplish it within
> the command instead of a management class. There were situations I
> chose to implement management classes though, for example, I had a class
> that managed all the media playing on a media player I am building...
> It just didn't feel right broken into commands, just didn't feel very
> cohesive, although accomplishable through commands, just felt better in
> a singleton class.... Especially since I was going to be using these
> same functions across many different commands and didn't want to rewrite
> the logic in each command.
>
>
>
> ________________________________
>
> From: [EMAIL PROTECTED]ups.com [mailto:[EMAIL PROTECTED]ups.com] On
> Behalf Of Derrick Grigg
> Sent: Wednesday, October 25, 2006 12:11 PM
> To: [EMAIL PROTECTED]ups.com
> Subject: [flexcoders] Cairngorm, dispatching application events and
> managing states
>
>
>
> Here's a question for any Cairngorm devotees to weigh in on.
>
> I have an application that has many seperate parts that function
> independently of each other. Each part uses the centralized Cairngorm
> fare (FrontController, ModelLocator, Commands etc). For most parts
> using the ModelLocator and bound properties (ie
> dataProvider={model.users}) works perfect for keeping everything in
> order.
>
> One case where this seems to fall apart is when one part or the shell
> application needs to notify the other parts of something that has
> happened. For example, a user logs into the application. I can update
> the model.user to reflect a value object for the new user and the
> various components that need to update on this do, BUT, what to do
> when I need something programatic to occur in one of the parts.
>
> I have tried unsuccessfully to use the 'mx.binding' classes. I think
> the issue there is that when you initially set the binding it is set
> to a specific instance of an object (ie model.user). When the user
> logs in I typically completely replace the model.user with a new user
> instance, which kills the bindings. The only way around this is to
> never replace object instances in the model but rather update them.
> Thinking this through though, that seems like a ticking time bomb. Any
> accidental overwrite of a instance in the model and all the bindings
> falls apart.
>
> What I have done in past, pre Cairngorm, applications it to create
> Manager classes, based on the Singleton pattern, that can dispatch
> events, and perform logic that doesn't really belong in a command or
> business delegate. For example an ApplicationManager class that can
> dispatch 'loggedIn' and 'loggedOut' events. Any part of the
> application can register as a listener and act appropriately upon
> receiving the event.
>
> My question then (to get to the point), is using a Manager class like
> this considered a best practice in the Cairngorm framework (mindframe)
> or is there a better or more acceptable method of doing what I would
> like to accomplish?
>
> Thanks in advance for any feedback,
>
> Derrick
>

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Reply via email to