symfony / ux

Symfony UX initiative: a JavaScript ecosystem for Symfony
https://ux.symfony.com/
MIT License
833 stars 306 forks source link

[ux-swup] Can't destroy swup object, only with DebugPlugin #136

Open vaiciant opened 3 years ago

vaiciant commented 3 years ago

Hello, I have a problem with the method destroy() in the object swup. I created my controller in stimulus so when the event connect is trigered it saved the object of swup, like the example of the readme:

_onConnect(event) {
     window.swupObj = event.detail.swup; // Swup instance
     console.log(window.swupObj);
}

It's saved to the window so I can access it in javascript, I want to call the method destroy() so this is what I writed:

function disableSwup() {
     this.swupObj.destroy();
}

It all went well until I disabled de data-debug like this:

<body {{ stimulus_controller({
          myswup: {},
          @symfony/ux-swup/swup': {}
          }) }}
          data-containers="{% block swup %}#swup{% endblock %}"
          data-theme="fade"
          {# data-debug="data-debug" add this attribute to enable debug #}
          data-animate-history-browsing="data-animate-history-browsing">

It didn't work and the javascript console throws an error:

Uncaught TypeError: Cannot read property 'formSubmit' of undefined
    at FormPlugin.unmount (index.js:67)
    at Swup.unuse (plugins.js:38)
    at index.js:209
    at Array.forEach (<anonymous>)
    at Swup.destroy (index.js:208)
    at disableSwup(login:147)
    at HTMLAnchorElement.onclick (login:106)

And the line index.jd:67 is in the _createClass(FormPlugin:

key: 'unmount',
        value: function unmount() {
            swup.delegatedListeners.formSubmit.destroy(); //<-THIS LINE
        }

Aparently the delegatedListeners are undefined when the DebuPlugin is not active, maybe I'm doing it wrong and not initializing the correct object and that's why it is undefined. It's working well whit the DebugPlugin enabled but I don't want to spam the console with all the events.

Is there a way to destroy the object of swup without the DebugPlugin??

Thanks in advance and amazing work in this, it all just works!

carsonbot commented 5 months ago

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?

carsonbot commented 5 months ago

Hello? This issue is about to be closed if nobody replies.

carsonbot commented 4 months ago

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!