Merge pull request #596 from VladimirTechMan/master

A few minor improvements to Node implementation code
This commit is contained in:
Anton Lavrenov 2019-03-06 19:27:45 -05:00 committed by GitHub
commit 26d09b5b88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1567,7 +1567,7 @@ export abstract class Node {
// start with stage and traverse downwards to self // start with stage and traverse downwards to self
this._eachAncestorReverse(function(node) { this._eachAncestorReverse(function(node) {
var transformsEnabled = node.transformsEnabled(); var transformsEnabled = node.getTransformsEnabled();
if (transformsEnabled === 'all') { if (transformsEnabled === 'all') {
at.multiply(node.getTransform()); at.multiply(node.getTransform());
@ -2007,8 +2007,7 @@ export abstract class Node {
* node.setAttr('x', 5); * node.setAttr('x', 5);
*/ */
setAttr(attr, val) { setAttr(attr, val) {
var method = SET + Util._capitalize(attr), var func = this[SET + Util._capitalize(attr)];
func = this[method];
if (Util._isFunction(func)) { if (Util._isFunction(func)) {
func.call(this, val); func.call(this, val);
@ -2019,10 +2018,8 @@ export abstract class Node {
return this; return this;
} }
_setAttr(key, val) { _setAttr(key, val) {
var oldVal; var oldVal = this.attrs[key];
oldVal = this.attrs[key]; if ((oldVal === val) && !Util.isObject(val)) {
var same = oldVal === val;
if (same && !Util.isObject(val)) {
return; return;
} }
if (val === undefined || val === null) { if (val === undefined || val === null) {
@ -2047,28 +2044,17 @@ export abstract class Node {
} }
} }
_fireAndBubble(eventType, evt, compareShape?) { _fireAndBubble(eventType, evt, compareShape?) {
var okayToRun = true;
if (evt && this.nodeType === SHAPE) { if (evt && this.nodeType === SHAPE) {
evt.target = this; evt.target = this;
} }
if ( var shouldStop =
eventType === MOUSEENTER && (eventType === MOUSEENTER || eventType === MOUSELEAVE) &&
compareShape && compareShape &&
(this._id === compareShape._id || (this._id === compareShape._id ||
(this.isAncestorOf && this.isAncestorOf(compareShape))) (this.isAncestorOf && this.isAncestorOf(compareShape)));
) {
okayToRun = false; if (!shouldStop) {
} else if (
eventType === MOUSELEAVE &&
compareShape &&
(this._id === compareShape._id ||
(this.isAncestorOf && this.isAncestorOf(compareShape)))
) {
okayToRun = false;
}
if (okayToRun) {
this._fire(eventType, evt); this._fire(eventType, evt);
// simulate event bubbling // simulate event bubbling
@ -2101,11 +2087,11 @@ export abstract class Node {
var events = this.eventListeners[eventType], var events = this.eventListeners[eventType],
i; i;
evt = evt || {};
evt.currentTarget = this;
evt.type = eventType;
if (events) { if (events) {
evt = evt || {};
evt.currentTarget = this;
evt.type = eventType;
for (i = 0; i < events.length; i++) { for (i = 0; i < events.length; i++) {
events[i].handler.call(this, evt); events[i].handler.call(this, evt);
} }