visible attr is now cacheable

This commit is contained in:
Eric Rowell
2013-08-09 23:00:35 -07:00
parent 41dea5300a
commit a0a2d9a676
3 changed files with 49 additions and 39 deletions

View File

@@ -1,39 +1,40 @@
(function() { (function() {
// CONSTANTS // CONSTANTS
var ADD = 'add', var ADD = 'add',
SPACE = ' ', B = 'b',
EMPTY_STRING = '',
DOT = '.',
GET = 'get',
PRIVATE_GET = '_get',
SET = 'set',
SHAPE = 'Shape',
STAGE = 'Stage',
X = 'x',
Y = 'y',
UPPER_X = 'X',
UPPER_Y = 'Y',
KINETIC = 'kinetic',
BEFORE = 'before', BEFORE = 'before',
BLACK = 'black',
CHANGE = 'Change', CHANGE = 'Change',
CHILDREN = 'children',
DEG = 'Deg',
DOT = '.',
EMPTY_STRING = '',
G = 'g',
GET = 'get',
HASH = '#',
ID = 'id', ID = 'id',
NAME = 'name', KINETIC = 'kinetic',
MOUSEENTER = 'mouseenter', MOUSEENTER = 'mouseenter',
MOUSELEAVE = 'mouseleave', MOUSELEAVE = 'mouseleave',
DEG = 'Deg', NAME = 'name',
ON = 'on',
OFF = 'off', OFF = 'off',
BLACK = 'black', ON = 'on',
RGB = 'RGB', PRIVATE_GET = '_get',
R = 'r', R = 'r',
G = 'g', RGB = 'RGB',
B = 'b', SET = 'set',
UPPER_R = 'R', SHAPE = 'Shape',
UPPER_G = 'G', SPACE = ' ',
UPPER_B = 'B', STAGE = 'Stage',
HASH = '#',
CHILDREN = 'children',
TRANSFORM = 'transform', TRANSFORM = 'transform',
UPPER_B = 'B',
UPPER_G = 'G',
UPPER_R = 'R',
UPPER_X = 'X',
UPPER_Y = 'Y',
VISIBLE = 'visible',
X = 'x',
Y = 'y',
CACHE_MAP = { CACHE_MAP = {
x: TRANSFORM, x: TRANSFORM,
@@ -43,7 +44,9 @@
scaleX: TRANSFORM, scaleX: TRANSFORM,
scaleY: TRANSFORM, scaleY: TRANSFORM,
skewX: TRANSFORM, skewX: TRANSFORM,
skewY: TRANSFORM skewY: TRANSFORM,
visible: VISIBLE
}; };
Kinetic.Util.addMethods(Kinetic.Node, { Kinetic.Util.addMethods(Kinetic.Node, {
@@ -64,7 +67,7 @@
var cache = this.cache[attr]; var cache = this.cache[attr];
// if not cached, we need to set it using the private getter method. // if not cached, we need to set it using the private getter method.
if (!cache) { if (cache === undefined) {
this.cache[attr] = privateGetter.call(this); this.cache[attr] = privateGetter.call(this);
} }
@@ -306,6 +309,9 @@
* @memberof Kinetic.Node.prototype * @memberof Kinetic.Node.prototype
*/ */
getVisible: function() { getVisible: function() {
return this._getCache(VISIBLE, this._getVisible);
},
_getVisible: function() {
var visible = this.attrs.visible, var visible = this.attrs.visible,
parent = this.getParent(); parent = this.getParent();

View File

@@ -8,7 +8,7 @@
<script src="../js/performanceTests.js"></script> <script src="../js/performanceTests.js"></script>
<!-- versions --> <!-- versions -->
<!--
<script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.5.2.min.js"></script> <script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.5.2.min.js"></script>
<script> <script>
run(Kinetic); run(Kinetic);
@@ -28,7 +28,7 @@
<script> <script>
run(Kinetic); run(Kinetic);
</script> </script>
-->
<script src="../../dist/kinetic-dev.js"></script> <script src="../../dist/kinetic-dev.js"></script>
<script> <script>
run(Kinetic); run(Kinetic);

View File

@@ -89,7 +89,7 @@ Test.Modules.NODE = {
test(circle.getAbsoluteOpacity() === 0.25, 'abs opacity should be 0.25'); test(circle.getAbsoluteOpacity() === 0.25, 'abs opacity should be 0.25');
test(layer.getAbsoluteOpacity() === 0.5, 'abs opacity should be 0.5'); test(layer.getAbsoluteOpacity() === 0.5, 'abs opacity should be 0.5');
}, },
'transformation matrix caching': function(containerId) { '*caching': function(containerId) {
var stage = new Kinetic.Stage({ var stage = new Kinetic.Stage({
container: containerId, container: containerId,
width: 578, width: 578,
@@ -110,19 +110,23 @@ Test.Modules.NODE = {
layer.add(circle); layer.add(circle);
stage.add(layer); stage.add(layer);
test(circle.cache.transform, '2) circle transform cache should be present'); // transform cache
test(circle.cache.transform, '2) circle transform cache should be primed');
console.log(circle.cache.transform)
circle.setX(100); circle.setX(100);
console.log(circle.cache.transform)
test(!circle.cache.transform, '3) circle transform cache should be empty'); test(!circle.cache.transform, '3) circle transform cache should be empty');
layer.draw(); layer.draw();
test(circle.cache.transform, '4) circle transform cache should be primed');
test(circle.cache.transform, '4) circle transform cache should be present'); // visible cache
test(circle.cache.visible === true, '5) circle visible cache should be primed');
circle.hide();
test(circle.cache.visible === undefined, '6) circle visible cache should be empty');
stage.draw();
test(circle.cache.visible === false, '7) circle visible cache should be primed');
circle.show();
test(circle.cache.visible === undefined, '8) circle visible cache should be empty');
stage.draw();
test(circle.cache.visible === true, '9) circle visible cache should be primed');
}, },
'test pixel ratio toDataURL': function(containerId) { 'test pixel ratio toDataURL': function(containerId) {