Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Welcome, Guest. Please login or register.
June 28, 2017, 10:28:20 AM
Home Help Search Login Register
News: Please DM @puremvc on Twitter to gain forum access. Spambots are why we can't have nice things.
Pages: [1] 2 3 4
Print
Author Topic: first project with pureMVC  (Read 40100 times)
danieleUg
Courseware Beta
Full Member
***
Posts: 28


View Profile
« on: July 07, 2007, 05:18:01 AM »

Hi Cliff,
I just starting a new project and I have chosen PureMVC instead Cairngorm. I have read all documentations and play a but with the demo (very usefull, thanks).
Now in this project I have some points and I would like to have a suggestion what's the best way to achieve:
- the APP_STARTUP must to read a XML config file
- I must to wait that the config is loaded, parse it and read some resources (other XML and background images)
- when all is loaded I can show the view.

What is the best way to make it?

Best,
   Daniele
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2870



View Profile WWW
« Reply #1 on: July 07, 2007, 09:15:57 AM »

Although you may not be intending to build an AIR app here, it would be worth your time to:


CodePeek does exactly what you are describing. The application:

  • Is not visible to start with (nor is its NativeWindow, so you can't even see it at all yet.) In Flex, you'd have something like a ViewStack with a splash screen as your first child.
  • Instantiates the ApplicationFacade
  • Application creationComplete handler sends APP_STARTUP Notification
  • Controller executes ApplicationStartupCommand
  • ApplicationStartupCommand calls ModelPrepCommand
  • ModelPrepCommand registers Proxies
  • Two of those Proxies read XML files (from the disk with AIR, you'd call a service with Flex)
  • One of those XML files is the Preferences XML db, which has the WindowMetrics data for positioning the window on the desktop. The CodePeekPrefsProxy creates and registers a WindowMetricsProxy to handle that entity in the Prefs file.
  • ApplicationStartupCommand calls ViewPrepCommand
  • ViewPrepCommand gets the WindowMetricsProxy, and sends an appropriate Notification
  • The StageMediator listens for the various notifications for affecting the desktop window position and display state
  • Once the window position has been restored, the StageMediator will detect a DISPLAY_STATE_CHANGE, MOVE and/or RESIZE events and will issue the VIEW_SHOW_WINDOW notification.
  • The StageMediator listens for this Notification (yes, its perfectly fine for a Mediator to Notify itself), and will make the Window visible.
  • The ApplicationMediator is also listening for VIEW_SHOW_WINDOW, and sets the Application's showControls property to true
  • The Application has its visible property bound to showControls, so it shows itself (within the Window which is now visible as well). There is an associated effect that causes the whole app to slide in at this point.

You wouldn't need the StageMediator or WindowMetrics stuff in your Flex app but much of this is the same. Essentially we don't show the goods till everything is on the shelves and we're ready open the doors to the public. You'll want to prep your Model followed by the View. so the startup sequence is the same.

However, the XML database Proxy creation and registration is synchronous in CodePeek. That is to say, when we register those Proxies, they read the stuff off disk in a blocking fashion and our code follows along. When the Proxy is created, the data is there. If you examine the CodePeekSearchProxy, you'll see how you might work your async service stuff. The CodeSearchProxy doesn't get called at startup, but it shows how to do an asyncrhonous RemoteProxy.

Some of your Proxies will send off requests to remote services when they are created. You'll create and register them just the same. However, when their services return, they will send Notifications that either a Command and or various Mediators will respond to, and eventually 'turn on' the UI by doing something like sending a Notification that the ApplicationMediator responds to by setting a value on the Application that causes the ViewStack selectedIndex to change, for instance.

You might have a complex startup situation where the creation of Proxies send off multiple requests for data and you want to turn on the UI only after ALL the services have returned and been properly responded to.

In this case, I suggest having a StartupMonitorProxy created and registered that holds a simple count of the number of startup services which must return before turning on the View.

Have each of the services called at startup send a STARTUP_RESULT notification when the data comes in, which is listened for by a StartupMonitorCommand.

The StartupMonitorCommand will, each time it is executed, get the StartupMonitorProxy and call a decrement method.

After calling the decrement method, the StartupMonitorCommand will ask the StartupMonitorProxy for the count and if the count has reached zero then we know all the services have returned, and so it will send a VIEW_SHOW_CONTROLS Notification, which will be responded to by one or more Mediators who 'turn on' the View by setting properties on their stewarded View Components.

Hope this helps!





Logged
danieleUg
Courseware Beta
Full Member
***
Posts: 28


View Profile
« Reply #2 on: July 09, 2007, 07:59:37 AM »

Hi Cliff,
thanks a lot for you help!
Logged
danieleUg
Courseware Beta
Full Member
***
Posts: 28


View Profile
« Reply #3 on: July 14, 2007, 04:46:26 PM »

Hi Cliff,
I have other questions for you:

- my Flex applycation read a config file using a Proxy. When a part of application (Mediator or other Proxy) need to get a config value can retrieve the proxy and call it?
ie:
configProxy = configProxy ( facade.retrieveProxy( configProxy .NAME ) );
configProxy.getValue('myValueKey');

- my application have a chat build with Flash Media Server, I think that also in this case I must to have a proxy class that make the connection with FMS and talk with it, right? But when a Mediator need to send a message to FMS (ie send the chat text) is better that retrieve the Proxy and call a method or send a notification for the proxy?

Thanks
   Daniele
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2870



View Profile WWW
« Reply #4 on: July 14, 2007, 08:42:42 PM »

You have it just right. Retrieve the Proxy from anywhere, and act upon the methods and properties you choose to expose for manipulating and referring to its Data Object.

A Proxy should talk to FDS and expose a getter cast to ArrayCollection that your Mediator can retrieve a reference and set as a property on its View Component, which is in turn has, for instance, an editable DataGrid's dataProvider bound to it.

-=Cliff>
Logged
danieleUg
Courseware Beta
Full Member
***
Posts: 28


View Profile
« Reply #5 on: July 17, 2007, 07:46:52 AM »

Hi Cliff,
I have made a little demo called Application Skeleton and I have implemented the startup sequence that read some resources:
- a configuration file
- a XML with localized text
- and other.

In the main view there is a example how to read localized text from the proxy.
I don't know if I have made all well, but I hope that it can help other people.

Best
  Daniele
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2870



View Profile WWW
« Reply #6 on: July 17, 2007, 09:24:33 AM »

Daniele,

Sounds great, where can we see it?

-=Cliff>
Logged
danieleUg
Courseware Beta
Full Member
***
Posts: 28


View Profile
« Reply #7 on: July 17, 2007, 09:50:35 AM »

Cliff,
there is the attach with source in my last post, but you can see it online:

Demo:
http://dev.ugoletti.com/puremvc/ApplicationSkeleton.swf

Source:
http://dev.ugoletti.com/puremvc/ApplicationSkeleton.zip
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2870



View Profile WWW
« Reply #8 on: July 18, 2007, 10:37:30 AM »

Daniele,

You've really done a great job here! It looks like something people could build off of pretty easily.

Here are my suggestions:

  • Zip the project folder rather than its contents, so when someone unzips it, they get one folder, and don't have to create one first. This cost me a Version point on PureMVC  Tongue


  • Move the business package under Model. Only a Proxy talks to it, so it shouldn't clutter the namespace at the MVC level. (the CafeTownsend demo has it at that level to make friendly with the Cairngorm folk, but it's not really a recommended practice I'd want to perpetuate with PureMVC.

    The Model tier is roundly in charge of communicating with remote services if necessary. It could be done inside the Proxy, as with CodePeek, or with a Business Delegate, as you've done here, but either way it will happen within the Model tier.

    Further, the Delegate pattern is only really useful to us if multiple Proxies will communicate with the same service the Delegate talks to, although it's not improper to use it if only one Proxy talks to it. It's a good division of responsibility, and I'm not suggesting its removal, only noting here for posterity that a good way to begin an app is to have the service logic inside the Proxy, and then later refactor it into a Delegate at the first call for reuse.

    One goal of the framework is to promote a 'simple as possible but no simpler' approach. Fewer actors will help newbies to design patterns and n-tier architecture grasp what's going on faster.


  • And for the same reason, move the flex/helpers package to  model/helpers, since it is the Proxies that use it to parse their data files.

Again, Daniele, you did a super job here. The implementation of the StartupMonitorProxy is especially well done illustrating the use of data from the first loaded file affecting the subsequent calls.

If you wouldn't mind writing a little something about it, I'd love to feature it as a demo. It would be most helpful for people to get a feel for how to turn it into their own thing.

-=Cliff>
Logged
danieleUg
Courseware Beta
Full Member
***
Posts: 28


View Profile
« Reply #9 on: July 18, 2007, 02:24:36 PM »

  • Zip the project folder rather than its contents, so when someone unzips it, they get one folder, and don't have to create one first. This cost me a Version point on PureMVC  Tongue



ok

  • Move the business package under Model. Only a Proxy talks to it, so it shouldn't clutter the namespace at the MVC level. (the CafeTownsend demo has it at that level to make friendly with the Cairngorm folk, but it's not really a recommended practice I'd want to perpetuate with PureMVC.

    The Model tier is roundly in charge of communicating with remote services if necessary. It could be done inside the Proxy, as with CodePeek, or with a Business Delegate, as you've done here, but either way it will happen within the Model tier.
this means that we have model/business folder with delegate files.

Further, the Delegate pattern is only really useful to us if multiple Proxies will communicate with the same service the Delegate talks to, although it's not improper to use it if only one Proxy talks to it. It's a good division of responsibility, and I'm not suggesting its removal, only noting here for posterity that a good way to begin an app is to have the service logic inside the Proxy, and then later refactor it into a Delegate at the first call for reuse.

you are right, but in this example we have 2 proxy that use the same delegate

  • And for the same reason, move the flex/helpers package to  model/helpers, since it is the Proxies that use it to parse their data files.

ok

If you wouldn't mind writing a little something about it, I'd love to feature it as a demo. It would be most helpful for people to get a feel for how to turn it into their own thing.

sure, I have posted the example because I think that can be usefull for others. I will try to write something but my english isn't so good Smiley
Where I can send the final file?

Daniele
[/list]
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2870



View Profile WWW
« Reply #10 on: July 18, 2007, 02:39:12 PM »

Daniele,

I will be happy to help with getting some documentation together and present it here as a demo people can actually get started from. It might be helpful to create a second demo based upon this one, to show the direction someone might take to use it.

You can email me at cliff@puremvc.org

Also, I see you're using Flash Develop. I haven't tried it yet, but it looks good. Did you use Michael Ramirez's PureMVC Project plugin?

-=Cliff>
Logged
danieleUg
Courseware Beta
Full Member
***
Posts: 28


View Profile
« Reply #11 on: July 18, 2007, 02:50:03 PM »

Daniele,

I will be happy to help with getting some documentation together and present it here as a demo people can actually get started from. It might be helpful to create a second demo based upon this one, to show the direction someone might take to use it.

You can email me at cliff@puremvc.org

thanks I will contact in private.

Also, I see you're using Flash Develop. I haven't tried it yet, but it looks good. Did you use Michael Ramirez's PureMVC Project plugin?

unfortunaly no, I have tried but I get a lot of errors, I don't have time to write to him but I will do ASAP.


Daniele
Logged
danieleUg
Courseware Beta
Full Member
***
Posts: 28


View Profile
« Reply #12 on: July 22, 2007, 07:00:18 AM »

Hi Cliff,
I have update the demo:

http://dev.ugoletti.com/puremvc/ApplicationSkeleton.zip

Changelog:
- updated to pureMVC 1.5
- now the ApplicationFacade.getConfigProxy() and ApplicationFacade.getResourceProxy() are static methods
- removed unused code

Daniele
Logged
achegedus
Courseware Beta
Newbie
***
Posts: 1


View Profile Email
« Reply #13 on: September 17, 2007, 01:35:30 PM »

Hey Cliff and Daniele,
I'm having trouble with this demo.  I keep getting a sandbox security error when i'm trying to load an xml file.  The xml isn't on a different domain, so I'm not sure what's happening.

Any suggestions?

Thanks,
Adam
Logged
danieleUg
Courseware Beta
Full Member
***
Posts: 28


View Profile
« Reply #14 on: October 12, 2007, 03:34:45 PM »

Hi Adam,
I hope that you have already solved you issue, sorry but I'm very busy.
I think that you have to manage your player security settings:

http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager.html

Best
  Daniele
Logged
Pages: [1] 2 3 4
Print
Jump to: