Taiwan's pivot away from China offers a lesson for democracies