tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/311-what-logic-can-be-put-inside-view-component-best-practice-questionRobotlegs: Discussion 2018-10-18T16:35:18Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/32763502010-10-08T10:16:46Z2010-10-08T14:26:03ZWhat logic can be put inside view component - Best practice question.<div><p>Oops, I accidentally put it as resolved. Could some moderator please reopen it. Thanks.</p></div>Flex Incubatortag:robotlegs.tenderapp.com,2009-10-18:Comment/32763502010-10-08T10:25:35Z2010-10-08T10:25:35ZWhat logic can be put inside view component - Best practice question.<div><p>Hi there, it does seem to be open now - maybe someone did it before I got there.</p>
<p>In short, I put most view-logic in the view, for sure. Visibility, transitions, positioning etc all live inside the view.</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/32763502010-10-08T10:31:48Z2010-10-08T14:26:03ZWhat logic can be put inside view component - Best practice question.<div><p>Aha, thanks. Because I thought that view components should only have visual elements, and should not have any other code.</p>
<p>Ilya.</p></div>Flex Incubatortag:robotlegs.tenderapp.com,2009-10-18:Comment/32763502010-10-08T10:40:21Z2010-10-08T10:40:21ZWhat logic can be put inside view component - Best practice question.<div><p>Hello Ilya,</p>
<p>"As I understand view components should not have any logic in it (well, under "logic" I mean some code which process data, do something etc)."</p>
<p>A better way to think about it is: the view component should not have any "application" logic in it. Likewise, the "application" should not have any view logic in it.</p>
<p>"1)Let's say that the toggling of the visibility of the shape will not influence any other part of the app - it will not change model, it will not run some command and so on. So, can i put the code to toggle the visibility inside the same view component in this case? Will it be correct? Or i still need to have some Command for this purpose?"</p>
<p>The view component should handle it's own state. The application shouldn't know (or care) about how the view component works.</p>
<p>"2)In the second case the information of the visibility of the shape is stored in Model. So, as I understand the correct solution will be to have some Command which do the job, something like if(toggled) shape.visible = false. Ok, but what if i need tweening? What if I do not want just to hide the shape with visible=false, but to tween its alpha. Where should I put the code for Tweening?"</p>
<p>Again, the application should not know (or care) about how the view component does its work. Your view component should expose an API and only be manipulated through that API. In your case you are exposing a low-level detail (the <code>visible</code> property) where you should be exposing a high-level API (something like <code>show()</code> and <code>hide()</code>). Now your view component can change how it performs the show/hide functionality, for example by implementing some tweening, without affecting any other part of the app.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/32763502010-10-08T10:49:31Z2010-10-08T14:26:04ZWhat logic can be put inside view component - Best practice question.<div><p>Thanks! BTW, I read a lot about Robotlegs' quick support. I see now that this is absolutely true! And nice that you reply even on such newbie questions :)</p>
<p>Ilya.</p></div>Flex Incubator