mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
implement off
with callbacks
This commit is contained in:
parent
3de52cac83
commit
8894d75a44
@ -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
|
||||
|
||||
|
2
konva.min.js
vendored
2
konva.min.js
vendored
File diff suppressed because one or more lines are too long
1958
src/Node.js
1958
src/Node.js
File diff suppressed because it is too large
Load Diff
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user