Skip to content

Commit

Permalink
Dropzone.destroy() removes itself from Dropzone.instances now.
Browse files Browse the repository at this point in the history
#changelog fixes #401
  • Loading branch information
enyo committed Dec 7, 2013
1 parent 25f8fab commit 797bae6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/dropzone.coffee
Expand Up @@ -576,6 +576,7 @@ class Dropzone extends Em
@hiddenFileInput.parentNode.removeChild @hiddenFileInput
@hiddenFileInput = null
delete @element.dropzone
Dropzone.instances.splice Dropzone.instances.indexOf(this), 1


updateTotalUploadProgress: ->
Expand Down
38 changes: 22 additions & 16 deletions test/test.coffee
Expand Up @@ -663,31 +663,37 @@ describe "Dropzone", ->

describe ".destroy()", ->
it "should properly cancel all pending uploads and remove all file references", (done) ->
dropzone.accept = (file, done) -> done()
dropzone.accept = (file, done) -> done()

dropzone.options.parallelUploads = 1
dropzone.options.parallelUploads = 1

dropzone.addFile getMockFile()
dropzone.addFile getMockFile()
dropzone.addFile getMockFile()
dropzone.addFile getMockFile()


setTimeout ->
dropzone.getUploadingFiles().length.should.equal 1
dropzone.getQueuedFiles().length.should.equal 1
dropzone.files.length.should.equal 2
setTimeout ->
dropzone.getUploadingFiles().length.should.equal 1
dropzone.getQueuedFiles().length.should.equal 1
dropzone.files.length.should.equal 2

sinon.spy dropzone, "disable"
sinon.spy dropzone, "disable"

dropzone.destroy()
dropzone.destroy()

dropzone.disable.callCount.should.equal 1
element.should.not.have.property "dropzone"
done()
, 10
dropzone.disable.callCount.should.equal 1
element.should.not.have.property "dropzone"
done()
, 10

it "should be able to create instance of dropzone on the same element after destroy", ->
dropzone.destroy()
( -> new Dropzone element, maxFilesize: 4, url: "url", acceptedMimeTypes: "audio/*,image/png", uploadprogress: -> ).should.not.throw( Error )
dropzone.destroy()
( -> new Dropzone element, maxFilesize: 4, url: "url", acceptedMimeTypes: "audio/*,image/png", uploadprogress: -> ).should.not.throw( Error )

it "should remove itself from Dropzone.instances", ->
(Dropzone.instances.indexOf(dropzone) != -1).should.be.ok
dropzone.destroy()
(Dropzone.instances.indexOf(dropzone) == -1).should.be.ok



describe ".filesize()", ->
Expand Down

0 comments on commit 797bae6

Please sign in to comment.