Skip to content

Commit

Permalink
Backport 2.x : The remove event is emitted on already removed eleme…
Browse files Browse the repository at this point in the history
…nts #2074 #2075
maxkfranz committed Mar 8, 2018
1 parent 1d25ee8 commit c9a1668
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/collection/index.js
Original file line number Diff line number Diff line change
@@ -521,7 +521,7 @@ elesfn.remove = function( notifyRenderer ){

function add( ele ){
var alreadyAdded = elesToRemoveIds[ ele.id() ];
if( alreadyAdded ){
if( ele.removed() || alreadyAdded ){
return;
} else {
elesToRemoveIds[ ele.id() ] = true;
25 changes: 25 additions & 0 deletions test/collection-graph-manipulation.js
Original file line number Diff line number Diff line change
@@ -51,6 +51,31 @@ describe('Collection graph manipulation', function(){
expect( cy.$('#n1n2') ).to.have.length(0);
});

it('should not emit the remove event on an already removed element', function(){
var n1 = cy.$('#n1');
var emitted = false;

n1.remove();

n1.on('remove', function(){ emitted = true; });

n1.remove();

expect(emitted).to.be.false;
});

it('should only emit the remove event once', function(){
var n1 = cy.$('#n1');
var emits = 0;

n1.on('remove', function(){ emits++; });

n1.remove();
n1.remove();

expect(emits).to.equal(1);
});

});

describe('ele.removed()', function(){

0 comments on commit c9a1668

Please sign in to comment.