Skip to content

Commit

Permalink
Merge pull request #1247 from transloadit/feature/react-uppy-change
Browse files Browse the repository at this point in the history
 react: Allow changing instance in `uppy` prop
  • Loading branch information
goto-bus-stop committed Jan 28, 2019
2 parents a8c596c + 53a362e commit 097c6ef
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 12 deletions.
19 changes: 17 additions & 2 deletions packages/@uppy/react/src/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ const h = React.createElement

class Dashboard extends React.Component {
componentDidMount () {
this.installPlugin()
}

componentDidUpdate (prevProps) {
if (prevProps.uppy !== this.props.uppy) {
this.uninstallPlugin(prevProps)
this.installPlugin()
}
}

componentWillUnmount () {
this.uninstallPlugin()
}

installPlugin () {
const uppy = this.props.uppy
const options = Object.assign(
{ id: 'react:Dashboard' },
Expand All @@ -23,8 +38,8 @@ class Dashboard extends React.Component {
this.plugin = uppy.getPlugin(options.id)
}

componentWillUnmount () {
const uppy = this.props.uppy
uninstallPlugin (props = this.props) {
const uppy = props.uppy

uppy.removePlugin(this.plugin)
}
Expand Down
19 changes: 17 additions & 2 deletions packages/@uppy/react/src/DashboardModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ const h = React.createElement

class DashboardModal extends React.Component {
componentDidMount () {
this.installPlugin()
}

componentDidUpdate (prevProps) {
if (prevProps.uppy !== this.props.uppy) {
this.uninstallPlugin(prevProps)
this.installPlugin()
}
}

componentWillUnmount () {
this.uninstallPlugin()
}

installPlugin () {
const uppy = this.props.uppy
const options = Object.assign(
{ id: 'react:DashboardModal' },
Expand All @@ -34,8 +49,8 @@ class DashboardModal extends React.Component {
}
}

componentWillUnmount () {
const uppy = this.props.uppy
uninstallPlugin (props = this.props) {
const uppy = props.uppy

uppy.removePlugin(this.plugin)
}
Expand Down
19 changes: 17 additions & 2 deletions packages/@uppy/react/src/DragDrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ const h = React.createElement

class DragDrop extends React.Component {
componentDidMount () {
this.installPlugin()
}

componentDidUpdate (prevProps) {
if (prevProps.uppy !== this.props.uppy) {
this.uninstallPlugin(prevProps)
this.installPlugin()
}
}

componentWillUnmount () {
this.uninstallPlugin()
}

installPlugin () {
const uppy = this.props.uppy
const options = Object.assign(
{ id: 'react:DragDrop' },
Expand All @@ -24,8 +39,8 @@ class DragDrop extends React.Component {
this.plugin = uppy.getPlugin(options.id)
}

componentWillUnmount () {
const uppy = this.props.uppy
uninstallPlugin (props = this.props) {
const uppy = props.uppy

uppy.removePlugin(this.plugin)
}
Expand Down
19 changes: 17 additions & 2 deletions packages/@uppy/react/src/ProgressBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ const h = React.createElement

class ProgressBar extends React.Component {
componentDidMount () {
this.installPlugin()
}

componentDidUpdate (prevProps) {
if (prevProps.uppy !== this.props.uppy) {
this.uninstallPlugin(prevProps)
this.installPlugin()
}
}

componentWillUnmount () {
this.uninstallPlugin()
}

installPlugin () {
const uppy = this.props.uppy
const options = Object.assign(
{ id: 'react:ProgressBar' },
Expand All @@ -24,8 +39,8 @@ class ProgressBar extends React.Component {
this.plugin = uppy.getPlugin(options.id)
}

componentWillUnmount () {
const uppy = this.props.uppy
uninstallPlugin (props = this.props) {
const uppy = props.uppy

uppy.removePlugin(this.plugin)
}
Expand Down
19 changes: 17 additions & 2 deletions packages/@uppy/react/src/StatusBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ const h = React.createElement

class StatusBar extends React.Component {
componentDidMount () {
this.installPlugin()
}

componentDidUpdate (prevProps) {
if (prevProps.uppy !== this.props.uppy) {
this.uninstallPlugin(prevProps)
this.installPlugin()
}
}

componentWillUnmount () {
this.uninstallPlugin()
}

installPlugin () {
const uppy = this.props.uppy
const options = Object.assign(
{ id: 'react:StatusBar' },
Expand All @@ -25,8 +40,8 @@ class StatusBar extends React.Component {
this.plugin = uppy.getPlugin(options.id)
}

componentWillUnmount () {
const uppy = this.props.uppy
uninstallPlugin (props = this.props) {
const uppy = props.uppy

uppy.removePlugin(this.plugin)
}
Expand Down
19 changes: 17 additions & 2 deletions packages/@uppy/react/src/Wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,29 @@ class UppyWrapper extends React.Component {
}

componentDidMount () {
this.installPlugin()
}

componentDidUpdate (prevProps) {
if (prevProps.uppy !== this.props.uppy) {
this.uninstallPlugin(prevProps)
this.installPlugin()
}
}

componentWillUnmount () {
this.uninstallPlugin()
}

installPlugin () {
const plugin = this.props.uppy
.getPlugin(this.props.plugin)

plugin.mount(this.container, plugin)
}

componentWillUnmount () {
const plugin = this.props.uppy
uninstallPlugin (props = this.props) {
const plugin = props.uppy
.getPlugin(this.props.plugin)

plugin.unmount()
Expand Down

0 comments on commit 097c6ef

Please sign in to comment.