Last active
November 3, 2017 22:47
-
-
Save richardwillars/857e845cbedc6695ba8e1861b4b1e50e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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?