Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

be more strict on when not to re render #3594

Merged
merged 4 commits into from
Dec 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"process": true
},
"rules": {
"semi": 2,
"eqeqeq": 2,
"no-eq-null": 2,
"no-eval": 2,
Expand Down
2 changes: 1 addition & 1 deletion src/amd/requirejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
window.fabric = fabric;

if (typeof define === 'function' && define.amd) {
define([], function() { return fabric });
define([], function() { return fabric; });
}
4 changes: 2 additions & 2 deletions src/mixins/canvas_events.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
*/
_onContextMenu: function (e) {
if (this.stopContextMenu) {
e.stopPropagation()
e.stopPropagation();
e.preventDefault();
}
return false;
Expand Down Expand Up @@ -266,7 +266,7 @@
_shouldRender: function(target, pointer) {
var activeObject = this.getActiveGroup() || this.getActiveObject();

if (activeObject && activeObject.isEditing) {
if (activeObject && activeObject.isEditing && target === activeObject) {
// if we mouse up/down over a editing textbox a cursor change,
// there is no need to re render
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/mixins/canvas_serialization.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
_this[property] = enlivedObject[0];
loaded[property] = true;
callback && callback();
})
});
}
else {
this['set' + fabric.util.string.capitalize(property, true)](value, function() {
Expand Down
4 changes: 2 additions & 2 deletions src/mixins/stateful.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
}
else if (origValue instanceof Array) {
if (origValue.length !== currentValue.length) {
return false
return false;
}
for (var i = 0, len = origValue.length; i < len; i++) {
if (origValue[i] !== currentValue[i]) {
return false;
}
}
return true
return true;
}
else if (origValue && typeof origValue === 'object') {
if (!firstPass && Object.keys(origValue).length !== Object.keys(currentValue).length) {
Expand Down
2 changes: 1 addition & 1 deletion src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
this.contextContainer = this.nodeCanvas.getContext('2d');
this.contextCache = this.nodeCacheCanvas.getContext('2d');
this.Font = Canvas.Font;
}
};

/** @ignore */
fabric.StaticCanvas.prototype.createPNGStream = function() {
Expand Down
4 changes: 2 additions & 2 deletions src/shapes/group.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
*/
isCacheDirty: function() {
if (this.callSuper('isCacheDirty')) {
return true
return true;
}
if (!this.statefullCache) {
return false;
Expand All @@ -305,7 +305,7 @@
if (this._objects[i].isCacheDirty(true)) {
var dim = this._getNonTransformedDimensions();
this._cacheContext.clearRect(-dim.x / 2, -dim.y / 2, dim.x, dim.y);
return true
return true;
}
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/itext.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@
width += this._getWidthOfCharSpacing();
}
ctx.restore();
return width > 0 ? width : 0
return width > 0 ? width : 0;
},

/**
Expand Down
4 changes: 2 additions & 2 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -893,9 +893,9 @@
this.cacheHeight = height;
this.zoomX = zoomX;
this.zoomY = zoomY;
return true
return true;
}
return false
return false;
},

/**
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/path.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@
*/
toObject: function(propertiesToInclude) {
var o = extend(this.callSuper('toObject', ['sourcePath', 'pathOffset'].concat(propertiesToInclude)), {
path: this.path.map(function(item) { return item.slice() })
path: this.path.map(function(item) { return item.slice(); })
});
return o;
},
Expand Down
4 changes: 2 additions & 2 deletions src/shapes/path_group.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
*/
isCacheDirty: function() {
if (this.callSuper('isCacheDirty')) {
return true
return true;
}
if (!this.statefullCache) {
return false;
Expand All @@ -121,7 +121,7 @@
if (this.paths[i].isCacheDirty(true)) {
var dim = this._getNonTransformedDimensions();
this._cacheContext.clearRect(-dim.x / 2, -dim.y / 2, dim.x, dim.y);
return true
return true;
}
}
return false;
Expand Down
8 changes: 4 additions & 4 deletions src/static_canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@
* @private
*/
_createCanvasElement: function(canvasEl) {
var element = fabric.util.createCanvasElement(canvasEl)
var element = fabric.util.createCanvasElement(canvasEl);
if (!element.style) {
element.style = { };
}
Expand Down Expand Up @@ -783,7 +783,7 @@
this.backgroundImage = null;
this.overlayImage = null;
this.backgroundColor = '';
this.overlayColor = ''
this.overlayColor = '';
if (this._hasITextHandlers) {
this.off('selection:cleared', this._canvasITextSelectionClearedHanlder);
this.off('object:selected', this._canvasITextSelectionClearedHanlder);
Expand Down Expand Up @@ -1082,12 +1082,12 @@
* @private
*/
__serializeBgOverlay: function(methodName, propertiesToInclude) {
var data = { }
var data = { };

if (this.backgroundColor) {
data.background = this.backgroundColor.toObject
? this.backgroundColor.toObject(propertiesToInclude)
: this.backgroundColor
: this.backgroundColor;
}

if (this.overlayColor) {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

function getAbsolutePath(path) {
var isAbsolute = /^https?:/.test(path);
if (isAbsolute) { return path };
if (isAbsolute) { return path; };
var imgEl = _createImageElement();
imgEl.src = path;
var src = imgEl.src;
Expand Down Expand Up @@ -258,7 +258,7 @@

test('before:selection:cleared', function() {
var isFired = false;
canvas.on('before:selection:cleared', function() { isFired = true });
canvas.on('before:selection:cleared', function() { isFired = true; });

canvas.add(new fabric.Rect());
canvas.remove(canvas.item(0));
Expand All @@ -274,7 +274,7 @@

test('selection:cleared', function() {
var isFired = false;
canvas.on('selection:cleared', function() { isFired = true });
canvas.on('selection:cleared', function() { isFired = true; });

canvas.add(new fabric.Rect());
canvas.remove(canvas.item(0));
Expand Down
4 changes: 2 additions & 2 deletions test/unit/canvas_static.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

function getAbsolutePath(path) {
var isAbsolute = /^https?:/.test(path);
if (isAbsolute) { return path };
if (isAbsolute) { return path; };
var imgEl = _createImageElement();
imgEl.src = path;
var src = imgEl.src;
Expand Down Expand Up @@ -113,7 +113,7 @@
function setSrc(img, src, callback) {
if (fabric.isLikelyNode) {
require('fs').readFile(src, function(err, imgData) {
if (err) { throw err };
if (err) { throw err; };
img.src = imgData;
img._src = src;
callback && callback();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@
obj.dirty = false;
equal(g1.dirty, false, 'Group has no dirty flag set');
obj.set('fill', 'red');
equal(obj.dirty, true, 'Obj has dirty flag set')
equal(obj.dirty, true, 'Obj has dirty flag set');
equal(g1.dirty, true, 'Group has dirty flag set');
});

Expand Down
4 changes: 2 additions & 2 deletions test/unit/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function getAbsolutePath(path) {
var isAbsolute = /^https?:/.test(path);
if (isAbsolute) { return path };
if (isAbsolute) { return path; };
var imgEl = _createImageElement();
imgEl.src = path;
var src = imgEl.src;
Expand Down Expand Up @@ -91,7 +91,7 @@
function setSrc(img, src, callback) {
if (fabric.isLikelyNode) {
require('fs').readFile(src, function(err, imgData) {
if (err) { throw err };
if (err) { throw err; };
img.src = imgData;
img._src = src;
callback && callback();
Expand Down
4 changes: 2 additions & 2 deletions test/unit/image_filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function getAbsolutePath(path) {
var isAbsolute = /^https?:/.test(path);
if (isAbsolute) { return path };
if (isAbsolute) { return path; };
var imgEl = _createImageElement();
imgEl.src = path;
var src = imgEl.src;
Expand Down Expand Up @@ -68,7 +68,7 @@
function setSrc(img, src, callback) {
if (fabric.isLikelyNode) {
require('fs').readFile(src, function(err, imgData) {
if (err) { throw err };
if (err) { throw err; };
img.src = imgData;
callback && callback();
});
Expand Down
2 changes: 1 addition & 1 deletion test/unit/itext.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
test('empty itext', function() {
var iText = new fabric.IText('');
equal(iText.width, iText.cursorWidth);
})
});

test('setSelectionEnd', function() {
var iText = new fabric.IText('test');
Expand Down
2 changes: 1 addition & 1 deletion test/unit/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@
top: 40,
width: 40,
height: 50,
clipTo: function(ctx) { ctx.arc(10, 10, 10, 0, Math.PI * 2, false) }
clipTo: function(ctx) { ctx.arc(10, 10, 10, 0, Math.PI * 2, false); }
});

equal(typeof object.clipTo, 'function');
Expand Down
6 changes: 3 additions & 3 deletions test/unit/pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
function setSrc(img, src, callback) {
if (fabric.isLikelyNode) {
require('fs').readFile(src, function(err, imgData) {
if (err) { throw err };
if (err) { throw err; };
img.src = imgData;
img._src = src;
callback && callback();
Expand Down Expand Up @@ -64,11 +64,11 @@
equal(object.offsetY, 0);

var patternWithGetSource = new fabric.Pattern({
source: function() {return fabric.document.createElement('canvas')}
source: function() {return fabric.document.createElement('canvas');}
});

var object2 = patternWithGetSource.toObject();
equal(object2.source, 'function () {return fabric.document.createElement(\'canvas\')}');
equal(object2.source, 'function () {return fabric.document.createElement(\'canvas\');}');
equal(object2.repeat, 'repeat');
});

Expand Down
36 changes: 18 additions & 18 deletions test/unit/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

QUnit.module('fabric.util');

function K (x) { return x }
function K (x) { return x; }

function _createImageElement() {
return fabric.isLikelyNode
Expand All @@ -12,7 +12,7 @@

function getAbsolutePath(path) {
var isAbsolute = /^https?:/.test(path);
if (isAbsolute) { return path };
if (isAbsolute) { return path; };
var imgEl = _createImageElement();
imgEl.src = path;
var src = imgEl.src;
Expand Down Expand Up @@ -267,7 +267,7 @@
ok(typeof fabric.util.toArray == 'function');

deepEqual(['x', 'y'], fabric.util.toArray({ 0: 'x', 1: 'y', length: 2 }));
deepEqual([1, 3], fabric.util.toArray((function(){ return arguments })(1, 3)));
deepEqual([1, 3], fabric.util.toArray((function(){ return arguments; })(1, 3)));

var nodelist = fabric.document.getElementsByTagName('div'),
converted = fabric.util.toArray(nodelist);
Expand Down Expand Up @@ -650,24 +650,24 @@
ok(typeof Array.prototype.filter === 'function');

var arr = [1,2,3,4,5];
deepEqual([3,4,5], arr.filter(function(val){ return val > 2 }));
deepEqual([], arr.filter(function(val){ return val > 5 }));
deepEqual([1,2], arr.filter(function(val){ return val <= 2 }));
deepEqual([3,4,5], arr.filter(function(val){ return val > 2; }));
deepEqual([], arr.filter(function(val){ return val > 5; }));
deepEqual([1,2], arr.filter(function(val){ return val <= 2; }));
});

test('Array.prototype.reduce', function() {
ok(typeof Array.prototype.reduce === 'function');

var arr = [1,2,3,4,5];
equal(15,
arr.reduce(function(memo, val) { return memo + val }), 0);
arr.reduce(function(memo, val) { return memo + val; }), 0);

deepEqual(['1!', '2!', '3!', '4!', '5!'],
arr.reduce(function(memo, val) { memo.push(val + '!'); return memo }, []));
arr.reduce(function(memo, val) { memo.push(val + '!'); return memo; }, []));

arr = 'foobar'.split('');
equal('f0o1o2b3a4r5',
arr.reduce(function(memo, val, index) { return memo + val + index }, ''));
arr.reduce(function(memo, val, index) { return memo + val + index; }, ''));
});

test('fabric.util.createClass', function() {
Expand Down Expand Up @@ -760,9 +760,9 @@
test('fabric.util.array.invoke', function() {
ok(typeof fabric.util.array.invoke === 'function');

var obj1 = { toString: function(){ return 'obj1' } };
var obj2 = { toString: function(){ return 'obj2' } };
var obj3 = { toString: function(){ return 'obj3' } };
var obj1 = { toString: function(){ return 'obj1'; } };
var obj2 = { toString: function(){ return 'obj2'; } };
var obj3 = { toString: function(){ return 'obj3'; } };

deepEqual(['obj1', 'obj2', 'obj3'],
fabric.util.array.invoke([obj1, obj2, obj3], 'toString'));
Expand All @@ -782,9 +782,9 @@
equal(-3, fabric.util.array.min([-1, -2, -3]));
equal('a', fabric.util.array.min(['a', 'c', 'b']));

var obj1 = { valueOf: function(){ return 1 } };
var obj2 = { valueOf: function(){ return 2 } };
var obj3 = { valueOf: function(){ return 3 } };
var obj1 = { valueOf: function(){ return 1; } };
var obj2 = { valueOf: function(){ return 2; } };
var obj3 = { valueOf: function(){ return 3; } };

equal(obj1, fabric.util.array.min([obj1, obj3, obj2]));
});
Expand All @@ -797,9 +797,9 @@
equal(-1, fabric.util.array.max([-1, -2, -3]));
equal('c', fabric.util.array.max(['a', 'c', 'b']));

var obj1 = { valueOf: function(){ return 1 } };
var obj2 = { valueOf: function(){ return 2 } };
var obj3 = { valueOf: function(){ return 3 } };
var obj1 = { valueOf: function(){ return 1; } };
var obj2 = { valueOf: function(){ return 2; } };
var obj3 = { valueOf: function(){ return 3; } };

equal(obj3, fabric.util.array.max([obj1, obj3, obj2]));
});
Expand Down