allow view events to be a function

Fixes #795