mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
perf fixes, transformer events
This commit is contained in:
36
src/Node.ts
36
src/Node.ts
@@ -961,24 +961,26 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
* });
|
||||
*/
|
||||
setAttrs(config: any) {
|
||||
var key, method;
|
||||
this._batchTransformChanges(() => {
|
||||
var key, method;
|
||||
if (!config) {
|
||||
return this;
|
||||
}
|
||||
for (key in config) {
|
||||
if (key === CHILDREN) {
|
||||
continue;
|
||||
}
|
||||
method = SET + Util._capitalize(key);
|
||||
// use setter if available
|
||||
if (Util._isFunction(this[method])) {
|
||||
this[method](config[key]);
|
||||
} else {
|
||||
// otherwise set directly
|
||||
this._setAttr(key, config[key]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!config) {
|
||||
return this;
|
||||
}
|
||||
for (key in config) {
|
||||
if (key === CHILDREN) {
|
||||
continue;
|
||||
}
|
||||
method = SET + Util._capitalize(key);
|
||||
// use setter if available
|
||||
if (Util._isFunction(this[method])) {
|
||||
this[method](config[key]);
|
||||
} else {
|
||||
// otherwise set directly
|
||||
this._setAttr(key, config[key]);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
|
@@ -314,10 +314,11 @@ export class Transformer extends Group {
|
||||
|
||||
_proxyDrag(node: Node) {
|
||||
let lastPos;
|
||||
node.on(`dragstart.${EVENTS_NAME}`, () => {
|
||||
node.on(`dragstart.${EVENTS_NAME}`, (e) => {
|
||||
lastPos = node.getAbsolutePosition();
|
||||
this.fire('dragstart', e);
|
||||
});
|
||||
node.on(`dragmove.${EVENTS_NAME}`, () => {
|
||||
node.on(`dragmove.${EVENTS_NAME}`, (e) => {
|
||||
if (!lastPos) {
|
||||
return;
|
||||
}
|
||||
@@ -337,6 +338,11 @@ export class Transformer extends Group {
|
||||
y: otherAbs.y + dy,
|
||||
});
|
||||
otherNode.startDrag();
|
||||
// TODO: how to trigger event after all nodes are dragged?
|
||||
this.fire('dragmove', e);
|
||||
});
|
||||
node.on(`dragend.${EVENTS_NAME}`, (e) => {
|
||||
this.fire('dragend', e);
|
||||
});
|
||||
lastPos = null;
|
||||
});
|
||||
|
Reference in New Issue
Block a user