Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Help with structure?  (Read 8806 times)
Slowburn
Newbie
*
Posts: 3


View Profile Email
« on: April 02, 2009, 11:42:07 »

Hello all,

I'm starting out using the pureMVC framework, and have some questions regarding setup of my structure.

My application is using Flash CS4 + AIR.
The basic functionality is the app will first show a custom config dialogue window where a user can enter a directory path and some timer delays.  On every delay, the app will poll the specified directory and collect the files inside. After this is complete the files ( images ) will be sent to a tile grid and displayed/modified.

My current structure is this:
StartupCommand - start ModelPrepCommand & ViewPrepCommand
ModelPrepCommand - registers ConfigProxy and TileGridProxy
ViewPrepCommand - registers AppMediator and send notification to SHOW config panel

PollDirectoryCommand - polls the specified directory and sends notification of new files ( or add them diretly to proxy/mediator?)
TogglePollingCommand - starts/stops the polling timer ( can I call a proxy from a mediator to do this directly?  is that good practice? )

App - the Stage view component
AppProxy - constructs timers for polling directory and image changes
AppMediator - constructs the Config component/mediator & TileGrid component/mediator

ConfigPanel - the view component, with field inputs
ConfigProxy - holds data for the view component
ConfigMediator - hides/shows the panel via notification

TileGrid - the view component(s)
TileGridProxy - Holds the files that-are/to-be displayed
TileGridMediator - Displays/modifies the files via notification

My uncertainty is if I'm on the right track.  do I set up the timers in the Proxy or the Mediator?
Also, should the PollDirectoryCommand be combined with the model?

Any help is appreciated.  thanks.
Logged

Thomas Schemmer
Senior Flash Developer/Architect
Sonic Boom Creative Media
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: April 02, 2009, 03:52:28 »

It looks like yore on the right track. To answer your embedded questions:

Yes, you can call proxies from mediators. The primary concern of seperating the view from the model has actually been done by the mediator if you've built you component and mediator correctly. That is to say (most importantly) the business entity on the Model side (the Proxy) knows nothing of the view component(s) to which it supplies data, and can therefore be used in another app altogether. And yor view component(s) know nothing of the business entities of the Model tier, OR of the Mediator that adapts them to the system and so they, too may be reused elsewhere, even without PureMVC.


So the mediators knowing the proxies is no problem. If you'd be making the same proxy calls from multiple mediators, it can be worthwhile to refactor those calls into commands, but you're balancing complexity and maintainability, so I usually only create the command when it becomes apparent that there is a DRYness issue; repeating the same code in multiple places. A good candidate for a command doing the proxy interaction instead of a mediator is a menu option that might be triggered from multiple places; keystroke, menu click, or a button all generated by different components and governed by multiple mediators, for instance.

The other question of timers, I'd create those with commands and have the callback on the command itself, as it can sometimes be difficult to debug anonymous functions passed to timers. If the callback is on the command, then you can set a breakpoint in the callback and when the debugger stops there you can drill into the command's facade reference, and drill down through the model, view, and controller to inspect every registered command mapping, every proxy and its data, and every mediator and its view hierarchy. With an anonymous function you cant see anything but its tiny scope.

-=Cliff>
Logged
Slowburn
Newbie
*
Posts: 3


View Profile Email
« Reply #2 on: April 02, 2009, 05:19:05 »

Thanks Cliff,

A little more help on timers, if you please.
If I create a timer in a command how is it possible to modify information for the timer ( i.e. start/stop or modify the delay setting ).
I would be using a timer to poll a directory and my ConfigProxy provides information like the path and delay time. Polling is setup as a command, it uses the synchronous AIR File methods to get the data and sends a notification to listening mediators ready for it's contents. Currently I have a Proxy invoking a Timer to keep it going so it is always running unless it's told to stop.

If the timer is in a Command, is it possible for it to store a reference to a timer? Should this rather be in a mediator?
Logged

Thomas Schemmer
Senior Flash Developer/Architect
Sonic Boom Creative Media
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: April 03, 2009, 04:21:47 »

If you make a method on the command be the callback, the the command lives on after execution because the timer has a reference to it. Then you kick it off again after it returns from within the callback. Whenever you stop it and the callback method complete for the last time, the command goes away. If your wanting it to be more durable, you could put it in a mediator or the proxy where you have it is fine. It all depends on the durability you're seeking.

-=Cliff>

Logged
Slowburn
Newbie
*
Posts: 3


View Profile Email
« Reply #4 on: April 03, 2009, 06:16:17 »

Awesome,

Thanks for your help Cliff.
Logged

Thomas Schemmer
Senior Flash Developer/Architect
Sonic Boom Creative Media
Pages: [1]
Print