fix "same value" detection in setAttr. fix #378

This commit is contained in:
Anton Lavrenov 2018-04-11 09:01:10 +07:00
parent 76d3282fcf
commit f8bd25cbfe
6 changed files with 52 additions and 5 deletions

View File

@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
* some bugs fixes for `group.getClientRect()` * some bugs fixes for `group.getClientRect()`
* `Konva.Arrow` will not draw dash for pointers * `Konva.Arrow` will not draw dash for pointers
* setAttr will trigger change event if new value is the same Object
## [2.0.2][2018-03-15] ## [2.0.2][2018-03-15]

View File

@ -352,7 +352,10 @@
*/ */
/** /**
* Transform constructor * Transform constructor. Transform object is a private class of Konva framework.
* In most of the cases you don't need to use it in your app.
* But there is a documentation for that class in case you still want
* to make some manual calculations.
* @constructor * @constructor
* @param {Array} [m] Optional six-element matrix * @param {Array} [m] Optional six-element matrix
* @memberof Konva * @memberof Konva
@ -732,6 +735,10 @@
_isString: function(obj) { _isString: function(obj) {
return Object.prototype.toString.call(obj) === OBJECT_STRING; return Object.prototype.toString.call(obj) === OBJECT_STRING;
}, },
// arrays are objects too
isObject: function(val) {
return val instanceof Object;
},
isValidSelector: function(selector) { isValidSelector: function(selector) {
if (typeof selector !== 'string') { if (typeof selector !== 'string') {
return false; return false;
@ -4244,7 +4251,8 @@
_setAttr: function(key, val) { _setAttr: function(key, val) {
var oldVal; var oldVal;
oldVal = this.attrs[key]; oldVal = this.attrs[key];
if (oldVal === val) { var same = oldVal === val;
if (same && !Konva.Util.isObject(val)) {
return; return;
} }
if (val === undefined || val === null) { if (val === undefined || val === null) {

2
konva.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1879,7 +1879,8 @@
_setAttr: function(key, val) { _setAttr: function(key, val) {
var oldVal; var oldVal;
oldVal = this.attrs[key]; oldVal = this.attrs[key];
if (oldVal === val) { var same = oldVal === val;
if (same && !Konva.Util.isObject(val)) {
return; return;
} }
if (val === undefined || val === null) { if (val === undefined || val === null) {

View File

@ -107,7 +107,10 @@
*/ */
/** /**
* Transform constructor * Transform constructor. Transform object is a private class of Konva framework.
* In most of the cases you don't need to use it in your app.
* But there is a documentation for that class in case you still want
* to make some manual calculations.
* @constructor * @constructor
* @param {Array} [m] Optional six-element matrix * @param {Array} [m] Optional six-element matrix
* @memberof Konva * @memberof Konva
@ -487,6 +490,10 @@
_isString: function(obj) { _isString: function(obj) {
return Object.prototype.toString.call(obj) === OBJECT_STRING; return Object.prototype.toString.call(obj) === OBJECT_STRING;
}, },
// arrays are objects too
isObject: function(val) {
return val instanceof Object;
},
isValidSelector: function(selector) { isValidSelector: function(selector) {
if (typeof selector !== 'string') { if (typeof selector !== 'string') {
return false; return false;

View File

@ -309,4 +309,34 @@ suite('Line', function() {
layer2.hide(); layer2.hide();
compareLayers(layer, layer2); compareLayers(layer, layer2);
}); });
test('updating points with old mutable array should trigger recalculations', function() {
var stage = addStage();
var layer = new Konva.Layer();
var points = [-25, 50, 250, -30, 150, 50];
var blob = new Konva.Line({
x: 50,
y: 50,
points: points,
stroke: 'blue',
strokeWidth: 10,
draggable: true,
closed: true,
tension: 1
});
var tensionPoints = blob.getTensionPoints();
points.push(250, 100);
blob.setPoints(points);
layer.add(blob);
stage.add(layer);
assert.equal(
tensionPoints === blob.getTensionPoints(),
false,
'calculated points should change'
);
});
}); });