Skip to content

Conversation

Nerdinacan
Copy link
Contributor

@Nerdinacan Nerdinacan commented Feb 5, 2020

I ended up requiring a destroy event to tell when the underlying component the observer was observing had disappeared because no "leave" event was fired in that scenario.

Example usage scenario:

<div v-for="child in menuNodes" :key="child.key">
    <intersect
        @leave="hide(child.key, $event)"
        @enter="show(child.key, $event)"
        @destroyed="hide(child.key, $event)">
        <render-node :node="child" />
    </intersect>
</div>

Here I was wrapping each element from a list of slot contents with your component to be able to tell whether or not they had passed out of view, but the items on menuNodes list (of VNodes) are themselves dynamic meaning the list can change from the outside, which can cause the intersect component and associated contents to disappear without firing a "leave" event.

Admittedly you can fix it this way too:

import Intersect from "vue-intersect";

const FixedIntersect = {
    ...Intersect,
    destroyed() {
        this.$emit("destroyed");
        Intersect.destroyed.call(this);
    }
}

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 211b935 on Nerdinacan:added-destroy-event into e3d68e3 on heavyy:master.

@tkjaergaard tkjaergaard merged commit de76dbf into heavyy:master Mar 5, 2020
@tkjaergaard
Copy link
Contributor

Thank you for PR, and sorry for late merge 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants