Skip to content

Commit

Permalink
Don't destroy Dropzone if files are in-flight
Browse files Browse the repository at this point in the history
  • Loading branch information
felixrieseberg committed Sep 21, 2015
1 parent 2f0c2b0 commit 6d33892
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 4 deletions.
26 changes: 24 additions & 2 deletions dist/dropzone.js
Original file line number Diff line number Diff line change
@@ -1,5 1,5 @@
/*!
* react-dropzone-component 0.5.3 (dev build at Mon, 21 Sep 2015 17:01:49 GMT) -
* react-dropzone-component 0.5.3 (dev build at Mon, 21 Sep 2015 17:29:41 GMT) -
* MIT Licensed
*/
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ReactDropzone = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '" o "'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o )s(r[o]);return s})({1:[function(require,module,exports){
Expand Down Expand Up @@ -68,14 68,36 @@ DropzoneComponent = React.createClass({displayName: "DropzoneComponent",
* Removes dropzone.js (and all its globals) if the component is being unmounted
*/
componentWillUnmount: function () {
this.dropzone = this.dropzone.destroy();
if (this.dropzone) {
var files = this.dropzone.getActiveFiles();

if (files.length > 0) {
// Well, seems like we still have stuff uploading.
// This is dirty, but let's keep trying to get rid
// of the dropzone until we're done here.
var destroyInterval = window.setInterval(function() {
if (this.queueDestroy = false) {
return window.clearInterval(destroyInterval);
}

if (this.dropzone.getActiveFiles().length === 0) {
this.dropzone = this.dropzone.destroy();
return window.clearInterval(destroyInterval);
}
}.bind(this), 500);
} else {
this.dropzone = this.dropzone.destroy();
}
}
},

/**
* React 'componentDidUpdate'
* If the Dropzone hasn't been created, create it
*/
componentDidUpdate: function () {
this.queueDestroy = false;

if (!this.dropzone) {
this.dropzone = new Dropzone(React.findDOMNode(this), this.getDjsConfig());
}
Expand Down
24 changes: 23 additions & 1 deletion lib/dropzone.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 63,36 @@ DropzoneComponent = React.createClass({displayName: "DropzoneComponent",
* Removes dropzone.js (and all its globals) if the component is being unmounted
*/
componentWillUnmount: function () {
this.dropzone = this.dropzone.destroy();
if (this.dropzone) {
var files = this.dropzone.getActiveFiles();

if (files.length > 0) {
// Well, seems like we still have stuff uploading.
// This is dirty, but let's keep trying to get rid
// of the dropzone until we're done here.
var destroyInterval = window.setInterval(function() {
if (this.queueDestroy = false) {
return window.clearInterval(destroyInterval);
}

if (this.dropzone.getActiveFiles().length === 0) {
this.dropzone = this.dropzone.destroy();
return window.clearInterval(destroyInterval);
}
}.bind(this), 500);
} else {
this.dropzone = this.dropzone.destroy();
}
}
},

/**
* React 'componentDidUpdate'
* If the Dropzone hasn't been created, create it
*/
componentDidUpdate: function () {
this.queueDestroy = false;

if (!this.dropzone) {
this.dropzone = new Dropzone(React.findDOMNode(this), this.getDjsConfig());
}
Expand Down
26 changes: 25 additions & 1 deletion src/dropzone.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 63,38 @@ DropzoneComponent = React.createClass({
* Removes dropzone.js (and all its globals) if the component is being unmounted
*/
componentWillUnmount: function () {
this.dropzone = this.dropzone.destroy();
if (this.dropzone) {
var files = this.dropzone.getActiveFiles();

if (files.length > 0) {
// Well, seems like we still have stuff uploading.
// This is dirty, but let's keep trying to get rid
// of the dropzone until we're done here.
this.queueDestroy = true;

var destroyInterval = window.setInterval(() => {
if (this.queueDestroy = false) {
return window.clearInterval(destroyInterval);
}

if (this.dropzone.getActiveFiles().length === 0) {
this.dropzone = this.dropzone.destroy();
return window.clearInterval(destroyInterval);
}
}, 500);
} else {
this.dropzone = this.dropzone.destroy();
}
}
},

/**
* React 'componentDidUpdate'
* If the Dropzone hasn't been created, create it
*/
componentDidUpdate: function () {
this.queueDestroy = false;

if (!this.dropzone) {
this.dropzone = new Dropzone(React.findDOMNode(this), this.getDjsConfig());
}
Expand Down

0 comments on commit 6d33892

Please sign in to comment.