Add scoped function

Add a function to handle the common enter-leave pattern.
How I see your comment now :)
As explained I'm not sure id this PR is useful at all ?