MagicLog.js 953 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const Plugin = require('@uppy/core/lib/Plugin')
  2. // import deepDiff from 'deep-diff'
  3. /**
  4. * Magic Log
  5. * Helps debug Uppy
  6. * inspired by https://github.com/yoshuawuyts/choo-log
  7. *
  8. */
  9. module.exports = class MagicLog extends Plugin {
  10. constructor (uppy, opts) {
  11. super(uppy, opts)
  12. this.type = 'debugger'
  13. this.id = 'MagicLog'
  14. this.title = 'Magic Log'
  15. // set default options
  16. const defaultOptions = {}
  17. // merge default options with the ones set by user
  18. this.opts = Object.assign({}, defaultOptions, opts)
  19. this.handleStateUpdate = this.handleStateUpdate.bind(this)
  20. }
  21. handleStateUpdate (prev, state, patch) {
  22. console.group('State')
  23. console.log('Prev', prev)
  24. console.log('Next', state)
  25. console.log('Patch', patch)
  26. console.groupEnd()
  27. }
  28. install () {
  29. this.uppy.on('state-update', this.handleStateUpdate)
  30. }
  31. uninstall () {
  32. this.uppy.off('state-update', this.handleStateUpdate)
  33. }
  34. }