LaTeX and Beamer: uncovering a tree node by node

Sometimes in Beamer, you want to reveal a tree node for node. With Beamer’s overlay commands, this is no problem (except that overlay commands must be placed within an additional set of curly braces, since Beamer eats them like Skittles). However, hiding and revealing the edges in between is a bit more fiddly. Here I present one way to go about it. The code, which is pretty much self-explanatory, is shown below and when inserted into a Beamer presentation (with the Berlin theme and transparent covering), produces the following output:

uncover-tree

% a wrapper to use \onslide within nodes,
% with the necessary extra surrounding accolades
\newcommand{\revealtext}[2][1-]{{\onslide<#1>{#2}}}
 
% a command to reveal either show or hide the edge from parent,
% based on the slide number
\makeatletter
\newcommand{\revealedge}[1]
{
	edge from parent%
	\ifnum#1>\beamer@slideinframe[draw=black!30]\else[draw=black]\fi
}
\makeatother
 
\begin{frame}
	\frametitle{Uncovering a tree (in an arbitrary order)}
	\begin{center}
		\begin{tikzpicture}
			\node {\revealtext{A}}
				child
				{
					node {\revealtext[2-]{B}}
					\revealedge{2}
					child
					{
						node {\revealtext[3-]{C}}
						\revealedge{3}
					}
					child
					{
						node {\revealtext[5-]{E}}
						\revealedge{5}
					}
				}
				child
				{
					node {\revealtext[4-]{D}}
					\revealedge{4}
				}
			;
		\end{tikzpicture}
	\end{center}
\end{frame}