mirror of
https://github.com/konvajs/konva.git
synced 2026-01-18 19:51:21 +08:00
reworked _getCache implementation
This commit is contained in:
46
src/Node.js
46
src/Node.js
@@ -46,10 +46,6 @@
|
|||||||
skewY: TRANSFORM
|
skewY: TRANSFORM
|
||||||
};
|
};
|
||||||
|
|
||||||
CACHE_ATTRS = {
|
|
||||||
transform: 1
|
|
||||||
};
|
|
||||||
|
|
||||||
Kinetic.Util.addMethods(Kinetic.Node, {
|
Kinetic.Util.addMethods(Kinetic.Node, {
|
||||||
_init: function(config) {
|
_init: function(config) {
|
||||||
this._id = Kinetic.Global.idCounter++;
|
this._id = Kinetic.Global.idCounter++;
|
||||||
@@ -64,24 +60,15 @@
|
|||||||
delete this.cache[cacheAttr];
|
delete this.cache[cacheAttr];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_getCache: function(attr, def){
|
_getCache: function(attr, privateGetter){
|
||||||
var val, cache;
|
var cache = this.cache[attr];
|
||||||
|
|
||||||
// if attr is cacheable
|
// if not cached, we need to set it using the private getter method.
|
||||||
if (CACHE_ATTRS[attr]) {
|
if (!cache) {
|
||||||
cache = this.cache[attr];
|
this.cache[attr] = privateGetter.call(this);
|
||||||
|
|
||||||
// if not cached, we need to set it using the private getter method.
|
|
||||||
if (!cache) {
|
|
||||||
this.cache[attr] = this[PRIVATE_GET + Kinetic.Util._capitalize(attr)]();
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.cache[attr];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
val = this.attrs[attr];
|
|
||||||
return val === undefined ? def : val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this.cache[attr];
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* bind events to the node. KineticJS supports mouseover, mousemove,
|
* bind events to the node. KineticJS supports mouseover, mousemove,
|
||||||
@@ -1148,6 +1135,14 @@
|
|||||||
},
|
},
|
||||||
isDraggable: function() {
|
isDraggable: function() {
|
||||||
return false;
|
return false;
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* get transform of the node
|
||||||
|
* @method
|
||||||
|
* @memberof Kinetic.Node.prototype
|
||||||
|
*/
|
||||||
|
getTransform: function() {
|
||||||
|
return this._getCache(TRANSFORM, this._getTransform);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1221,7 +1216,8 @@
|
|||||||
method = GET + Kinetic.Util._capitalize(attr);
|
method = GET + Kinetic.Util._capitalize(attr);
|
||||||
|
|
||||||
constructor.prototype[method] = function() {
|
constructor.prototype[method] = function() {
|
||||||
return this._getCache(attr, def);
|
var val = this.attrs[attr];
|
||||||
|
return val === undefined ? def : val;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
Kinetic.Node.addPointGetter = function(constructor, attr) {
|
Kinetic.Node.addPointGetter = function(constructor, attr) {
|
||||||
@@ -1727,14 +1723,6 @@
|
|||||||
* @param {Boolean} visible
|
* @param {Boolean} visible
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Kinetic.Node.addGetter(Kinetic.Node, 'transform');
|
|
||||||
/**
|
|
||||||
* get transform of the node
|
|
||||||
* name getTransform
|
|
||||||
* @method
|
|
||||||
* @memberof Kinetic.Node.prototype
|
|
||||||
*/
|
|
||||||
|
|
||||||
// aliases
|
// aliases
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user