Sunday, 19 October 2014

Declaring Seaside sub-components in the #children method

People often ask why they need to define the #children method on Seaside components. I wrote a long email today to the mailing list explaining how #children is currently used and why it's important and I thought it might be useful to post it here as well so it's easier to find and link to. 

When you render a child component you are implicitly defining a tree of components. #children simply allows the framework to walk the component tree explicitly. The reasons for needing to walk the tree explicitly have changed over time, which is part of the reason for the confusion.

At one point, for example, we used to walk the tree to give each component a chance to handle callbacks, so if your component wasn't in #children it would never even have seen its callbacks. That is no longer the case (which is actually a bit of a shame because decorations can no longer intercept them, but I digress).

If you look in the image for users of WAVisiblePresenterGuide and WAAllPresenterGuide, you will see the current cases where we need to traverse the tree:
  1. Calling #updateStates: for snapshotting/backtracking
  2. Calling #initialRequest: when a new session is started
  3. Executing tasks (they need to execute outside of the render phase to make sure the render phase does not have side effects)
  4. Calling #updateRoot:
  5. Calling #updateUrl:
  6. Displaying Halos for each component in development mode
  7. Generating the navigation path in WATree
  8. Detecting which components are visible/active to support delegation (#call:/#show:)
Keep in mind that basically all these things happen before rendering, so if you create new components inside #renderContentOn: they'll miss out: you should try to create your sub-components either when your component is initialized or during a callback. If your child component doesn't rely on any of the above (and doesn't use any child components itself that rely on any of these things) then technically everything will work fine without adding it to #children. But keep in mind that:
  • the framework may change in the future to traverse the tree for other reasons;
  • add-ons may depend on being able to walk the tree for other reasons; and
  • it's not great encapsulation to assume that, in the future, components you are rendering will never need any of the above nor start using sub-components that do. 
Finally, components are stateful by definition, so if you don't feel the need to persist your component between render phases, it probably shouldn't be a component. For stateless rendering you're better to subclass WAPainter directly or even WABrush: both of these are intended to be used and then thrown away and they will make it clearer in your mind whether or not you're using on things that depend on #children.


Willie Ames said...

I feel that with each new frontend framework, the amount of javascript code is increasing and increasing, to the point that, if I have a medium to large-sized application, my (pipelined) application.js may have a few hundreds of KBs. I'm now starting a new app using React, and with only a single CRUD it already has over 200 lines of React code defining some components. Should I only require these component files, and also any other javascript file that's not global, on the specific pages such as purevpn review where they are being used?

Anonymous said...

Informative article. A virtual private network, or just VPN, helps encrypt and secure your router against information theft, misuse and only fraud. A single DDWRT router VPN can protect traffic that is internet most of the networked computers, hence helping you save a huge expense for internet security and privacy. Furthermore, Purevpn will redress individual IPs also of every computer or device on the community, therefore helping you secure identities of computer on the World Wide Web.

zubair hussain said...

Hey Willie, you have shared an excellent review of PureVPN, I am a VPN user for 5 to 6 month I mostly use VPN to access geo-restricted content in the UK. Recently I bought Nord VPN, and it is fantastic.

georgperry said...

I feel that with each new frontend structure, the measure of javascript code is expanding and expanding, to the point that, in the event that I have a medium to huge estimated application, my (pipelined) application.js may have a couple of several KBs. I'm currently beginning another application utilizing React, and with just a solitary CRUD it as of now has more than 200 lines of React code characterizing a few segments. Would it be a good idea for me to just require these segment documents, and furthermore some other javascript record that is not worldwide, on the particular pages, for example, purevpn survey where they are being utilized?
Uk writing experts

John Shepherd said...

Do you find writing to be a difficult task? Have you procrastinated until the final month to write your dissertation? You do not have to panic just yet! With the assistance of British Dissertation Home, you can avail the dissertation writing services uk to get your dissertation written on any topic before the due date.

Amy Willor said...

A high-standard post with all imperative information about Assignment Help UK services. Looking forward to avail the premium services.

Steve Dalton said...

Do you find writing to be a tough undertaking? Have you procrastinated until the final month to jot down your dissertation? You should no longer panic simply yet! With the help of British Dissertation Home, you may avail the Quality Essay Writing Service UK to get your dissertation written on any subject matter earlier than the due date.

TECH FIRE said...

Many commentators were recommended purevpn, but make sure you have reviewed every vpns app before jump into conclusion. Check the detailed guide:

Amy Wong said...

Damn so cool just yesterday found this site and today I know what's what good best online casino sites Now plans to sit here all your free time and fun and productive

haryjohn8feb said...

Excellent and nice post. It will beneficial for everyone. Thanks for sharing such a wonderful post. Avail No 1 Essay writing Services UK from certified PhD writers. It is extremely helpful for me. You can email us at or Phone Number - 020 8144 9988

maxruselusa said...

Thank you for sharing this. The blog is very informative. The given blog tends to provide essential information about the changes and modifications of the Web application development company.

Herryjony said...

Tracy Isselhardt
Technology can often have its own disadvantages: vulnerability to cyber threats and of course hackers is definitely one of them. This has begun to apply to car technologies as well. Vehicle security is crucial and car companies want to ensure that hackers are kept away from their customers

Alina Smith said...

Astounding article. Interesting to peruse. I truly love to peruse such a decent article. Much obliged! continue shaking ..SPSS Help

assignment help said...

Really informative and inoperative, Thanks for the post and effort! Please keep sharing more such a blog. assignment helps

petterson said...

I like your post seaside for children but I think it can be very dangerous for small children
buy dissertation online