static Component* findComponentWithID (Component& c, const String& compId)
    {
        jassert (compId.isNotEmpty());
        if (c.getComponentID() == compId)
            return &c;

        for (int i = c.getNumChildComponents(); --i >= 0;)
            if (Component* const child = findComponentWithID (*c.getChildComponent (i), compId))
                return child;

        return nullptr;
    }
    Component* findComponentWithID (Component* const c, const String& compId)
    {
        jassert (compId.isNotEmpty());
        if (c->getComponentID() == compId)
            return c;

        for (int i = c->getNumChildComponents(); --i >= 0;)
        {
            Component* const child = findComponentWithID (c->getChildComponent (i), compId);

            if (child != nullptr)
                return child;
        }

        return nullptr;
    }
    static void updateComponent (ComponentBuilder& builder, const ValueTree& state)
    {
        if (Component* topLevelComp = builder.getManagedComponent())
        {
            ComponentBuilder::TypeHandler* const type = builder.getHandlerForState (state);
            const String uid (getStateId (state));

            if (type == nullptr || uid.isEmpty())
            {
                // ..handle the case where a child of the actual state node has changed.
                if (state.getParent().isValid())
                    updateComponent (builder, state.getParent());
            }
            else
            {
                if (Component* const changedComp = findComponentWithID (*topLevelComp, uid))
                    type->updateComponentFromState (changedComp, state);
            }
        }
    }