DEV Community

loading...

LinusBorg's (nor Other Expert's) Advice Not to be Followed Blindly

dexygen profile image George Jempty ・2 min read

I started working with Vue.js in 2017, and based on the profile I used at the time I see I posted thrice during my first 2 months. And LinusBorg (https://forum.vuejs.org/u/linusborg/summary), a core Vue.js team member, responded every time.

Ironically though, I never gleaned anything Vue-specific from his responses to apply to my problems, but rather, unknown to him, he turned out to be my "rubber duck" (https://en.wikipedia.org/wiki/Rubber_duck_debugging). He still helped me, it's just that in the end my issues never really were Vue-specific.

I was new to Vue at the time and other members already on the team when I joined had a bit of a head-start on me. Those other team members conveyed that it was best practice to remove event listeners in the beforeDestroy or destroyed life-cycle hooks, so we adopted that technique.

Months later though when I was mired in defect-remediation 95% of the time due to a business decision to change the back-end but shorten the deadline, one defect kept me busy for an entire day give or take, until I traced it back to event listeners being removed. The issue was that we had multiple components of a particular type on the page, and they could be added and removed, but when any single one of them got removed, the event listeners were removed for all of them :(

Within the last week while googling I found the following post of LinusBorg's on the Vue forum (https://forum.vuejs.org/t/adding-eventlistener-on-mounted/3337/3) wherein he stated, in 2016, that "you should simply use the destroyed() hook to remove the listener when the component is destroyed". Which made me wonder if my team members had possibly seen this?

So be careful about removing those event listeners in your beforeDestroy/destroyed hooks. And also when following expert advice, do so with a critical eye.

Discussion (0)

Forem Open with the Forem app