I've moved conditions out of the class to the top level, so they're no invoked each time when the directive is created
I've added disconnect() call on the observer when the directive is destroyed, since unobserve() just stops observing the element, but doesn't stop observing the entire viewport
disconnect()
call on the observer when the directive is destroyed, sinceunobserve()
just stops observing the element, but doesn't stop observing the entire viewport