mirror of
https://github.com/konvajs/konva.git
synced 2025-12-05 03:24:23 +08:00
bug fix - when setting a custom attr that points to self, the setAttrs method no longer gets stuck in a recursive loop throwing a stack overflow error. Also, objects that were instantiated from a class (non-literal objects) are no longer serializable
This commit is contained in:
@@ -120,7 +120,7 @@ Kinetic.GlobalObject = {
|
||||
}
|
||||
},
|
||||
/*
|
||||
* utilities
|
||||
* cherry-picked and modified utilities from underscore.js
|
||||
*/
|
||||
_isElement: function(obj) {
|
||||
return !!(obj && obj.nodeType == 1);
|
||||
@@ -138,6 +138,14 @@ Kinetic.GlobalObject = {
|
||||
_isNumber: function(obj) {
|
||||
return toString.call(obj) == '[object Number]';
|
||||
},
|
||||
_hasMethods: function(obj) {
|
||||
var names = [];
|
||||
for(var key in obj) {
|
||||
if(this._isFunction(obj[key]))
|
||||
names.push(key);
|
||||
}
|
||||
return names.length > 0;
|
||||
},
|
||||
/*
|
||||
* The argument can be:
|
||||
* - an integer (will be applied to both x and y)
|
||||
|
||||
@@ -157,10 +157,10 @@ Kinetic.Node.prototype = {
|
||||
}
|
||||
|
||||
/*
|
||||
* if property is an object, then add an empty object
|
||||
* if property is a pure object (no methods), then add an empty object
|
||||
* to the node and then traverse
|
||||
*/
|
||||
if(go._isObject(val) && !go._isArray(val) && !go._isElement(val)) {
|
||||
if(go._isObject(val) && !go._isArray(val) && !go._isElement(val) && !go._hasMethods(val)) {
|
||||
if(obj[key] === undefined) {
|
||||
obj[key] = {};
|
||||
}
|
||||
|
||||
22
src/Stage.js
22
src/Stage.js
@@ -182,17 +182,17 @@ Kinetic.Stage.prototype = {
|
||||
|
||||
function addNode(node) {
|
||||
var obj = {};
|
||||
|
||||
|
||||
var cleanAttrs = node.attrs;
|
||||
|
||||
// remove function, image, and DOM attrs
|
||||
for (var key in cleanAttrs) {
|
||||
var val = cleanAttrs[key];
|
||||
if (go._isFunction(val) || go._isElement(val)) {
|
||||
cleanAttrs[key] = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// remove function, image, DOM, and objects with methods
|
||||
for(var key in cleanAttrs) {
|
||||
var val = cleanAttrs[key];
|
||||
if(go._isFunction(val) || go._isElement(val) || go._hasMethods(val)) {
|
||||
cleanAttrs[key] = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
obj.attrs = cleanAttrs;
|
||||
|
||||
obj.nodeType = node.nodeType;
|
||||
@@ -394,7 +394,7 @@ Kinetic.Stage.prototype = {
|
||||
// draw layer and append canvas to container
|
||||
layer.draw();
|
||||
this.content.appendChild(layer.canvas);
|
||||
|
||||
|
||||
/*
|
||||
* set layer last draw time to zero
|
||||
* so that throttling doesn't take into account
|
||||
|
||||
Reference in New Issue
Block a user