I think that viewmode should disappear and the sidebar should just be a dom element rendered to the page. Then the code in sidebar would be abstracted out into something resembling a middleware step.