View/Sort cleanup: move stuff to root scope

Moved `applyView`, `applySort` and `viewState` to the root scope.

Fixes #1131.
Fixes #1132.