implement off with callbacks

This commit is contained in:
Anton Lavrenov 2018-01-12 11:05:12 +07:00
parent 3de52cac83
commit 8894d75a44
5 changed files with 2006 additions and 1955 deletions

View File

@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added
* new `Konva.Transformer` group that allow simple resize, and rotate of a shape.
* Add ability to remove event by callback `node.off('event', callback)`
## Changed

1958
konva.js

File diff suppressed because it is too large Load Diff

2
konva.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -1926,6 +1926,48 @@ suite('Node', function() {
layer.draw();
});
// ======================================================
test('remove event with with callback', function() {
var stage = addStage();
var layer = new Konva.Layer();
var circle = new Konva.Circle({
x: stage.getWidth() / 2,
y: stage.getHeight() / 2,
radius: 70,
fill: 'green',
stroke: 'black',
strokeWidth: 4,
name: 'myCircle'
});
stage.add(layer);
layer.add(circle);
layer.draw();
var event1 = 0;
var event2 = 0;
var callback1 = function() {
event1 += 1;
}
var callback2 = function() {
event2 += 1;
}
circle.on('event', callback1);
circle.on('event', callback2);
circle.fire('event');
assert.equal(event1, 1, 'event1 triggered once');
assert.equal(event2, 1, 'event2 triggered once');
circle.off('event', callback1);
circle.fire('event');
assert.equal(event1, 1, 'event1 still triggered once');
assert.equal(event2, 2, 'event2 triggered twice');
});
// ======================================================
test('simulate event bubble', function() {
var stage = addStage();