perf fixes, transformer events

This commit is contained in:
Anton Lavrenov
2020-06-16 12:16:53 -05:00
parent 1d8388eead
commit e22a98d656
6 changed files with 73 additions and 44 deletions

View File

@@ -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;
}
/**

View File

@@ -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;
});