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.

Wednesday 28 May 2014

Nine time zones, no jet lag!

Day 58 - London - 20,946 km traveled

We've crossed from the Pacific to the Atlantic by land and sea, covering nearly 21,000 km and 9 time zones! When we got home, what we really wanted was a proper cup of tea:



On the way back, we stopped off for the weekend to visit friends in Vilnius, Lithuania. This was a great way to mark the end the trip: it's a really picturesque, charming city with no shortage of great bars and restaurants. And with locals to show us around, we were able to sample some great ones (the cigarette lighter is for scale):



We broke up the final leg of the journey with a quick overnight stop in Warsaw and breakfast—good bread!—in Cologne before boarding the Eurostar back to St. Pancras International.

As usual, time is playing funny tricks: it feels like only a few weeks since we left but if we focus on all the places we've been, things we've done, and distance we've traveled, it's hard to believe it has only been two months. We're both amazed at how well the trip worked out and, given the constraints we had to work with, we're really happy with where and when we went, how long we spent in each place, where we stayed, and what we did; if we were doing the trip knowing what we know now, I don't think we'd change anything much. And we're already thinking about planning our next train trip: a December jaunt to the German Christmas markets.

Oh, and in all the time we were away, I think the trains ran on time almost to the minute. Until we hit Europe, that is!

Update (bonus): this thematically relevant xkcd comic coincidentally came out last week

Saturday 24 May 2014

60° North

Day 54 - Vilnius - 18,526 km travelled

Hot. That's the best word to describe our exit from St. Petersburg. We opted for 3rd class, where the train carriages didn't have air conditioning, and opening the tiny windows seemed to blow a lot of wind onto someone else's bunk without actually managing to circulate any air at all in the rest of the carriage. We lay on our beds wearing as little as possible, coated in films of sweat, trying to get some sleep before 2am when we knew we'd be woken up for the border crossing. We'd only worked out the uncivilized hour the day before—had we realized earlier we might have opted for a day train—but actually it was relatively painless compared to our earlier crossings: it took only an hour on the Russian side and 45 minutes on the Latvian and the whole process was pretty respectful of the fact that we were half asleep and sticking, half-undressed, to our bed sheets.

The train into St. Petersburg was air conditioned, which was great because St. Petersburg was hot too: highs of close to 30°C most days. Our beds—carriage 11, berths 18 and 20—would have been great too if it weren't for the conspicuous and total absence of a carriage 11 on the train. They sorted it out eventually with beds in another carriage.


St. Petersburg is an attractive city, spread out across several islands and sort of a cross between Amsterdam, Stockholm, Vienna, and Venice, which is not surprising given Peter's attraction to all things European. It's also much further north than I realized: we were still a month ahead of the solstice and the sun was already staying up until 10:40pm. One night we stayed out until 2am to watch the bridges over the river lift to allow ships to pass; this is a common activity and there were locals out socializing, running, roller blading, and so on well into the night. The bridges stay up for a few hours, so if you're caught on the wrong side of the river you basically just have to carry on partying until 5:00. The sky still wasn't pitch black when we went to bed. Next week is the start of the White Nights festival, which brings concerts and events all over the city to celebrate the season when darkness never falls.

One of the cultural highlights of St. Petersburg is the Hermitage, an art gallery housed in the old summer palace. I thought the combination of great art, fashion, and furniture shown off in magnificent, opulent architecture was wonderful. Wandering the palace rooms with their gilded ceilings, intricate floors, and amazingly fine mosaics was probably the best part, but you could absorb it passively without the feeling of dead, empty rooms that often comes with palace tours.

Another highlight for us was a trip to see the ballet La Bayadère at the Mariinsky Theatre. It was really impressive and quite beautiful. The first act had really great storytelling, though I was glad to have read a synopsis. The second act seemed to have been structured specifically to allow all the dancers to perform various solos and small group choreography; having only been to the ballet once in school I have no idea if this is common practice or not. Some of the routines were very impressive, though I did find the device wore a bit thin. The final act includes apparently one of the most famous scenes in the world of ballet, a dream scene with 32 ballerinas descending a ramp in single file. The whole act was wonderfully designed, lit, and choreographed for maximum visual effect. The whole experience was great.

We also really enjoyed our trip out to Peterhof, Russia's answer to the palace at Versailles. Tsar Peter filled the grounds with fountains, all running off gravity without a single pump. I actually found the fountains a bit underwhelming given how impressed everyone sounded in reviews and guidebooks, but the overall effect of the gardens was great and we spent longer than expected—most of the afternoon in the end—strolling around the grounds. Peter had a sense of humour too and there are a number of trick fountains that will soak unsuspecting visitors.

Monday 19 May 2014

Magnificent Moscow

Day 49 - Moscow - 17,160 km travelled

Moscow has been awesome.
I think we both expected to like it but were expecting it to be quite grey, bleak and dramatic more in a post-Soviet kind of way. In fact, it's a really beautiful city with a vibrant cafe culture, lots of lovely parks, and amazing architecture on top of the cathedrals and museums it's famous for. For me, our few days here have been one of the highlights of our trip.

We've spent a lot of time just wandering round, stopping for coffee and beers along the way.  There are a number of lovely parks that run along the river, that are really popular with tourists and locals alike. They're full of nice bars and cafes, lounge chairs and hammocks, bike paths, exhibitions, sports grounds etc. And at this time of year there were stages being set up everywhere for the festival of the white nights, which runs from the end of may to July.

One of my favourite spots was Vorobyevy Gory, a park near Moscow State university which is full of joggers, cyclists and picnickers in summer but turns into a ski park in the winter - with an enormous ski jump that looks like it lands in the river! From the top of the park you get an amazing panorama of the city, where you can spot the 'seven sisters' - seven sky scrapers designed in the Stalinist style (see photo).


We've really lucked out on three fronts in our four days here - we've had amazing sunshine, our visit has coincided with international museum day, which means all the museums were free, and we stumbled across a free concert by The Bolshoi theatre orchestra after enjoying an afternoon at the New Tretyakov gallery, which houses a brilliant collection of 20th century Soviet art. Julian and I usually have a two hour limit in museums and galleries but we happily spent most the day here as there was so much to see.

Yesterday we enjoyed an afternoon at the Pushkin gallery and then whiled away the rest of the day at a terrace cafe enjoying a bottle of wine and a couple of beers, indulging in some serious people watching. Muscovites are seriously well dressed - I've never seen such a concentration of stiletto heeled beautiful people. We both felt somewhat out of place in our quick dry t-shirts and hiking shoes. Slightly tipsy, we went back to our hostel just as six fire engines arrived to extinguish the kitchen fire on the third floor. Guess where our room was? Yes, next door!! Luckily, the fire didn't spread beyond the kitchen, which was completely gutted.


We were advised that no trip to Moscow is complete without a trip to the All Russia Exhibition Centre - a massive park with monuments to agriculture, industry, education, etc. and pavilions for each Soviet Republic. It was mostly built under Stalin to depict the achievements of the USSR and glorify the ideology of communism. All of the buildings were closed but the park was still full of tourists and locals alike, many of whom were roller blading.

In Moscow, it seems all the young beautiful people's preferred method of transport is roller blades and, since the exhibitions were closed, we (Julian) decided it was only right to rent some. I was pretty apprehensive - I've never never been rollerblading and wasn't sure that this was the time to find out how good/bad I am at it. I'm pleased to report that after a shaky start I actually wasn't too bad. I might even get a pair!!

Thursday 15 May 2014

The long train west, part 2

Day 45, 8:00 am local time - Train 81, 1,419 km from Moscow - 15,894 km traveled

I haven't a clue where we are. All seemed good at about 3:00 this morning when we stopped in what was presumably Yekaterinburg, though we were awoken there by someone trying to open our compartment door and thought our days of privacy might be over. They seemed to quickly move on to the next compartment, however, and the train carried on into the night.

Now that I'm awake, though, none of the kilometre posts line up with the descriptions in the guidebook anymore and I've realized that none of the remaining stations on the schedule posted in our carriage appear on the guidebook maps or vice versa. Either Russia, over the past few years, has systematically renamed all the towns within a day's travel of Moscow, or I guess we're taking a different route.
It seems a curious route though as we're currently crawling along a section of only single track that is crossing what seem like new bridges. We also keep passing little guard huts surrounded by barbed wire. Where are we I wonder? As long as the numbers on the posts keep going down, we at least know we're still heading for Moscow...


I took a walk to the back of the train yesterday—the second train I've tried this on—and got the same result in both cases: strange, almost intimidating looks from a few passengers in the open carriages and unfriendly glares from the carriage attendants at the back of the train, even when I made it clear I was just stretching my legs or taking a photograph. I guess Russians don't walk around trains, a fact confirmed by the almost deserted restaurant car last night.

They had an English menu, but it had only three choices on it so we decided instead to decipher the Russian menu with the help of Google Translate and our phrasebook. Identifying sections called Soups, Salads, Second Dishes, Sides, Sauces, and Desserts (how's that for sibilant alliteration?) we picked out two promising second dishes: one talking about pork tenderloin and onions, the other potatoes and mushrooms. Despite [thanks to?] the layer of oil, they tasted quite nice, but we may have misunderstood something and it's a good thing we don't mind sharing because, as you can hopefully tell from the photograph, neither was large enough to constitute a meal and a dish of potatoes can't really count as a more than a side dish, surely. At £18, we didn't feel we were getting great value. For now I think I'm just going to stay safely in my compartment.


I suppose we'll need to start adjusting to higher food prices though, as we should be officially back in Europe now: the obelisk marking the highest point in the Urals is at kilometre 1,777; we basically crossed the Urals in darkness but should have passed that point shortly after leaving Yekaterinburg. We're really looking forward to four days each in Moscow and St Petersburg and only a few meals of porridge and instant noodles stand between us!

[We are now running at a reasonable speed again and back on dual tracks... still a mystery where though :-)]

Wednesday 14 May 2014

The long train west

Day 44, 11:20 am local time - Train 81, 3,006 km from Moscow - 14,307 km traveled

We left Irkutsk at 1:17 am local time yesterday, though the clocks in the train station all said 20:17 because all trains in Russia run on Moscow time. This is particularly confusing when, as in our case, the time change spans midnight and you need to book the train for a different date than your actual departure.


In 36 hours, we've covered over 2000 km so far, crossed two timezones, and passed the halfway points of all the trans-Siberian routes from Beijing and Vladivostok. We're making good progress but certainly have a lot of kilometres still to go. The train trundles along at a pretty steady 60–70 km/h but makes quite a few stops: sometimes these are for just a minute or two to let people on or off, but we also make some 20–40 min stops in the tiniest places, presumably for some combination of providing a buffer to keep the train on time, allowing other trains to pass, topping up water, and emptying toilets. This train is the first since we left Japan to have toilets with holding tanks, which means they aren't closed in stations; they would have been more appreciated on the trains with 8-hour border crossings, but it's still one less thing to worry about.

I saw a couple with backpacks getting on the train in Irkutsk but pretty much everyone on the train seems Russian; certainly we're the only foreigners in our carriage. So far, we've been lucky enough to have a compartment to ourselves: this does mean we only have each other for company and haven't spent our nights drinking vodka, but it also means we've been pretty comfortable and have slept well. And after the woman who shared our compartment from Ulan Bator unpacked half a sheep from a cloth bag and laid it out on the bed to dry, we've really come to appreciate the benefits of having our own space.


So far we've been spending our time reading (sometimes out loud), playing cards, and looking out the window... not that there's a whole lot to see. The weather's lovely this morning though and the guide book gives us occasional kilometre markers to look out for. Our compartment hasn't turned into Lord of the Flies yet!

We're thinking we might go check out the dining car tonight but we've got a good supply of tea, instant noodles, and porridge which we can make with the free hot water in the samovar at the end of the carriage. And we've got fruit, bread, cheese, biscuits, and snacks to fill in the gaps. Plus a couple of bottles of wine of course. :-)

Monday 12 May 2014

Back in the saddle

Day 42 - 12,128 km travelled

We're just back from a fabulous few days on Olkhon island, the largest island on Lake Baikal. We stayed at Olga's guesthouse, where we enjoyed enormous portions of home cooked food.

The island is a tourist haven in the summer but at this time of year is fairly deserted. The main town felt a bit like a film set for a western, made up of ram shackled wooden huts and houses.

We were lucky enough to have two days of glorious sunshine although the lake was still partially frozen, which made for an impressive contrast with the golden sandy beach.

The island is a great place for hiking and cycling so we decided to get back in the saddle - this time mountain bikes rather than horses.


Now, before continuing, let me give you a bit of background to my cycling career: I was the last person is my class to learn to ride a bike, in fact it was such an event that the whole neighbourhood came out to watch when my stabilisers eventually came off. To cut a long story short, I'm not a natural cyclist.

We chose a 50km route across the island, over some rolling hills (which felt like mountains), through forest and alpine meadows. It was tough. I had to push my bike more than halfway up the first hill and it didn't get much easier. I'd like to blame it partly on the fact that I had a bike that was far too big - which made uphill particularly difficult and downhill particularly terrifying - but I'd just be making excuses. Julian didn't have to push once. It was only when I went over a steep summit and slammed on the back brake only to have my back wheel jump off the ground that I realised the brakes were the wrong way round - nobody told me that it's only in the UK that the back brake is on the left. Did I mention I'm not a natural cyclist!?

Physical challenges aside, it was a great day. The highlight was the halfway point, where the track meets the shore of the lake on the Bolshoi Sea side of the island. It was an eerily beautiful spot because the lake was perfectly calm and it was impossible to distinguish the water from the sky, meaning it looked a bit like the edge of the world.


On our second day we were reunited with the 'Soviet Jeep' for a tour of the northern cape. Our guide was an old Russian man who cooked us fish soup and served his wife's delicious fresh tomato salsa for lunch.

We finished off the trip with a banya - similar to a sauna - which is an important part of Russian life, particularly in winter when the temperature on the island hits -30 degrees.