Kinrany / vue-p5

Vue component for p5.js
125 stars 16 forks source link

`windowResized` may not be called as expected #30

Closed agm1984 closed 4 years ago

agm1984 commented 4 years ago

Hey I'm having an issue with the windowResized event.

        <vue-p5
            :additionalEvents="['windowResized']"
            @setup="setup"
            @draw="draw"
            @windowResized="windowResized"
        ></vue-p5>

These don't work for me. I found this issue thread: https://github.com/Kinrany/vue-p5/issues/11

In here, you recommended:

            document.addEventListener('resize', () => {
                sketch.resizeCanvas(window.innerWidth, window.innerHeight);
            });

That also doesn't work for me, and the issue is that document.addEventListener() doesn't work. When I change it to window, it starts working and correctly fires the resize event.

I figured I would make an issue for this in case anyone else encounters this. It will probably affect the generic/edge cases around :additionalEvents="[]" if it is calling document. in the library code.

Beyond that, nice work. I just ported over an ancient vanilla JavaScript "sacred geometry" generator, and the code is so much nicer to work with now via vue-p5.

Kinrany commented 4 years ago

Hi, thanks for the kind words!

Please try lowercase @windowresized instead of @windowResized. Also it's already supported, so you don't need :additionalEvents!

This is a gotcha multiple people have already had issues with, so I guess it's finally time for me to add FAQ :D

agm1984 commented 4 years ago

Thanks for the turbo reply velocity. I just tried and that did work. Thanks a lot.

Kinrany commented 4 years ago

You're welcome 🙂