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: command modifies viewComponent??  (Read 3726 times)
marcink
Jr. Member
**
Posts: 13


View Profile Email
« on: December 24, 2008, 02:49:35 »

hi all,

is it allowed to modify a viewComponent directly from a command?

i have a MacroAsyncCommand with three AsyncCommands: FadeOut, Update and FadeIn.
each of the subcommands modifies the view directly.

i know i could make it like: call 1st command from mediator, when 1st command sends notification that its finished, mediator modifies the view, then calls the 2nd command... and so on.
but with this, i would add lots of constants to the app.

i would like to know, if the first approach is allowed or not.

thanks!!
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: December 25, 2008, 06:20:01 »

Sometimes there are situations that require the view component to be updated in the way that you describe. In these cases, you can retrieve the mediator, and access its view component. You have to make the typed getter public on the mediator.

The only problem with this and why it is cautioned against is that it spreads around knowledge of the view component, such that if that component is modified, multiple actors may need to be refactored. This is why the mediator is generally the only point of contact with that component.

Ways to reduce code smell when you do this are to cleanly implement your 'API' of props and methods for the component so as to encapsulate as much of its internal implementation (which you should be doing as a matter of course to protect the mediator, but now its even more important). Consider making the component implement an interface and only make calls against the interface (i.e. The typed getter returns an interface type rather than a class).

-=Cliff>
Logged
marcink
Jr. Member
**
Posts: 13


View Profile Email
« Reply #2 on: December 25, 2008, 12:28:02 »

hi cliff,

thanks for the answer...
i'm quite new to patterns, so sometimes i'm not very confident hot to use it... :)

anyway, thanks!
Logged
Pages: [1]
Print