Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create onUnmount in UIPlugin for plugins that require clean up #3093

Merged
merged 5 commits into from
Aug 17, 2021

Conversation

Murderlon
Copy link
Member

@Murderlon Murderlon commented Aug 11, 2021

Fixes #3092

  • Create and call onUnmount in UIPlugin for plugins that require clean up
  • Update webcam stop to clean up when already recording
  • Update "Writing plugins" docs
  • Move onMount and onUnmount from BasePlugin into UIPlugin
  • Update types

@arturi
Copy link
Contributor

arturi commented Aug 11, 2021

I think plugins are only installed once, when they are .used, so we can’t actually uninstall plugin each time user clicks Cancel, because then they can’t return to it?

Screenshot 2021-08-11 at 11 55 51

@Murderlon
Copy link
Member Author

I think plugins are only installed once, when they are .used, so we can’t actually uninstall plugin each time user clicks Cancel, because then they can’t return to it?

Good point. I have now used inversion of control to let plugins define a onClose method which can be used for any clean up that a plugin may require in the dashboard when the user clicks cancel.

Perhaps this should be documented and/or added to UIPlugin?

@Murderlon Murderlon changed the title Uninstall active plugin when clicking "Cancel" Call plugin onClose in dashboard when clicking "Cancel" to perform clean up Aug 11, 2021
@arturi
Copy link
Contributor

arturi commented Aug 11, 2021

Yeah, good thinking! Is it similar to onMount, should it be onUnmount then?

@Murderlon
Copy link
Member Author

Yeah, good thinking! Is it similar to onMount, should it be onUnmount then?

We already have unmount in UIPlugin. Also good to note that for almost all plugins uninstall and unmount is enough. It's just for our dashboard use case that for instance webcam needs some cleanup when you click "cancel". So I'm not certain yet that it belongs in BasePlugin/UIPlugin. But the pattern of just adding this.onClose to the plugin class is currently only tribal knowledge, if you don't know you won't find it.

@arturi
Copy link
Contributor

arturi commented Aug 12, 2021

Yeah, that’s why I think if we have both this.onClose and this.unmount it might be confusing? The cleanup could be done in this.unmount just as well?

@Murderlon
Copy link
Member Author

Murderlon commented Aug 12, 2021

Yeah, that’s why I think if we have both this.onClose and this.unmount it might be confusing? The cleanup could be done in this.unmount just as well?

unmount is already defined in UIPlugin and I don't think we want to override this logic?

  unmount () {
    if (this.isTargetDOMEl) {
      this.el?.remove()
    }
  }

For instance, in webcam it is used here:

  uninstall () {
    this.stop()
    this.unmount()
  }

that's why I created onClose but I agree that it is basically the same thing as unmount. I'm also not sure about creating onUnmount in BasePlugin if unmount already exists in UIPlugin. But perhaps it would be a bit better than onClose.

@arturi
Copy link
Contributor

arturi commented Aug 12, 2021

I guess we could just copy whatever is in the unMount when re-defining it, but someone might forget to 🤔

@Murderlon Murderlon changed the title Call plugin onClose in dashboard when clicking "Cancel" to perform clean up Create onUnmount in BasePlugin for plugins that require clean up Aug 12, 2021
@Murderlon
Copy link
Member Author

I choose to create onUnmount in BasePlugin in the end because:

  • It is consistent. onMount already exists there while mount also exists in UIPlugin. Now the same alignment exists for unmount
  • It makes sense because mount and unmount do the actual (un)mouting while onX methods are used for additional side effects.

@arturi
Copy link
Contributor

arturi commented Aug 12, 2021

Yeah, this actually does make sense, awesome!

@Murderlon Murderlon added the Core label Aug 12, 2021
@arturi
Copy link
Contributor

arturi commented Aug 12, 2021

Should we update docs maybe https://uppy.io/docs/writing-plugins/?

packages/@uppy/webcam/src/index.js Outdated Show resolved Hide resolved
packages/@uppy/webcam/src/index.js Show resolved Hide resolved
packages/@uppy/webcam/src/index.js Outdated Show resolved Hide resolved
@Murderlon Murderlon changed the title Create onUnmount in BasePlugin for plugins that require clean up Create onUnmount in UIPlugin for plugins that require clean up Aug 17, 2021
@Murderlon Murderlon merged commit a3aac6b into main Aug 17, 2021
@Murderlon Murderlon deleted the webcam-cancel-recording branch August 17, 2021 12:52
Murderlon added a commit that referenced this pull request Aug 17, 2021
* 'main' of https://github.com/transloadit/uppy:
  Changelog for 1.31.0 and patches
  Strictly type uppy events (#3085)
  Create `onUnmount` in `UIPlugin` for plugins that require clean up (#3093)
  Companion improve logging (#3103)
  Fix `editFile` locale usage (#3108)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Webcam continues recording after pressing cancel, crashes
3 participants