Skip to content

Instantly share code, notes, and snippets.

@richardwillars
Last active November 3, 2017 22:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardwillars/857e845cbedc6695ba8e1861b4b1e50e to your computer and use it in GitHub Desktop.
Save richardwillars/857e845cbedc6695ba8e1861b4b1e50e to your computer and use it in GitHub Desktop.
import { Plugin } from 'uppy';
export default class ReduxEmitter extends Plugin {
constructor(core, opts) {
super(core, opts);
this.type = 'redux';
this.id = 'ReduxEmitter';
this.title = 'Redux Emitter';
// set default options
const defaultOptions = {};
// merge default options with the ones set by user
this.opts = Object.assign({}, defaultOptions, opts);
this.handleStateUpdate = this.handleStateUpdate.bind(this);
}
handleStateUpdate(prev, state, patch) {
this.opts.dispatch(this.opts.action(state)); // this dispatches a redux event with the new state
}
install() {
this.core.emitter.on('core:state-update', this.handleStateUpdate);
this.opts.dispatch(this.opts.action(this.core.state)); // set the initial redux state
}
uninstall() {
this.core.emitter.off('state-update', this.handleStateUpdate);
}
}
@oyeanuj
Copy link

oyeanuj commented Jun 7, 2017

@richardwillars This is interesting. So, since this is a plugin, does your component not deal with redux actions at all - let's uppy do the work? And is the idea that you are then using redux information for other things but not for actual upload related things?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment