Add scoped function

Add a function to handle the common enter-leave pattern.
Yep, that's fine.