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

feat(): remove deprecated code from older versions #6111

Merged
merged 7 commits into from
Feb 11, 2020
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
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## [4.0.0-beta.7]

Removal of deprecated methods / patterns. [#6111](https://github.com/fabricjs/fabric.js/pull/6111)
- removed Object.setShadow, and BaseBrush.setShadow. change `rect.setShadow(options)` to `rect.set('shadow', new fabric.Shadow(options))`
- removed Object.transformMatrix.
- removed `object:selected` event. use `selection:created`. In the callback you will still find `target` in the options, but also you will find `selected` with all the objects selected during that single event.
- removed Gradient.forObject. No alternative available.
- removed Object and canvas `clipTo`. Use Object.clipPath;
- removed Canvas.loadFromDatalessJSON, it was just an alias for `loadFromJSON`
- removed `observe`, `stopObserving`, `trigger` from observable. Keep using `on`, `off`, `fire`.
- removed the Object.set ability to take a function as a value. Was rather strange to use.
- removed Object.setGradient. Change `rect.setGradient(options)` with `rect.set('fill', new fabric.Gradient(otherOptions))`. The options format is slightly different, but keeping 2 formats does not really make sense.
- removed Object.setPatternFill. Change `rect.setPatternFill(options)` to `rect.set('fill', new fabric.Pattern(options))`;
- removed Object.setColor. Change `rect.setColor(color)` to `rect.set('fill', color)`
- removed fabric.util.customTransformMatrix. Use the replacement fabric.util.composeMatrix

## [4.0.0-beta.6]

fix(fabric.IText): exitEditing won't error on missing hiddenTextarea. [#6138](https://github.com/fabricjs/fabric.js/pull/6138)
Expand Down
11 changes: 0 additions & 11 deletions src/brushes/base_brush.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,6 @@ fabric.BaseBrush = fabric.util.createClass(/** @lends fabric.BaseBrush.prototype
*/
strokeDashArray: null,

/**
* Sets shadow of an object
* @param {Object|String} [options] Options object or string (e.g. "2px 2px 10px rgba(0,0,0,0.2)")
* @return {fabric.Object} thisArg
* @chainable
*/
setShadow: function(options) {
this.shadow = new fabric.Shadow(options);
return this;
},

/**
* Sets brush styles
* @private
Expand Down
2 changes: 1 addition & 1 deletion src/brushes/circle_brush.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fabric.CircleBrush = fabric.util.createClass(fabric.BaseBrush, /** @lends fabric
fill: point.fill
});

this.shadow && circle.setShadow(this.shadow);
this.shadow && (circle.shadow = new fabric.Shadow(this.shadow));

circles.push(circle);
}
Expand Down
2 changes: 1 addition & 1 deletion src/brushes/pencil_brush.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
});
if (this.shadow) {
this.shadow.affectStroke = true;
path.setShadow(this.shadow);
path.shadow = new fabric.Shadow(this.shadow);
}

return path;
Expand Down
2 changes: 1 addition & 1 deletion src/brushes/spray_brush.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fabric.SprayBrush = fabric.util.createClass( fabric.BaseBrush, /** @lends fabric
}

var group = new fabric.Group(rects);
this.shadow && group.setShadow(this.shadow);
this.shadow && group.set('shadow', new fabric.Shadow(this.shadow));
this.canvas.add(group);
this.canvas.fire('path:created', { path: group });

Expand Down
6 changes: 0 additions & 6 deletions src/canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* @fires object:scaling while an object is being scaled by controls
* @fires object:moving while an object is being dragged
* @fires object:skewing while an object is being skewed from the controls
* @fires object:selected this event is deprecated. use selection:created
*
* @fires before:transform before a transform is is started
* @fires before:selection:cleared
Expand Down Expand Up @@ -1150,11 +1149,6 @@
somethingChanged && this.fire('selection:updated', opt);
}
else if (objects.length > 0) {
// deprecated event
if (objects.length === 1) {
opt.target = added[0];
this.fire('object:selected', opt);
}
opt.selected = added;
// added for backward compatibility
opt.target = this._activeObject;
Expand Down
21 changes: 1 addition & 20 deletions src/gradient.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,27 +452,8 @@
});

return gradient;
},
/* _FROM_SVG_END_ */

/**
* Returns {@link fabric.Gradient} instance from its object representation
* this function is uniquely used by Object.setGradient and is deprecated with it.
* @static
* @deprecated since 3.4.0
* @memberOf fabric.Gradient
* @param {Object} obj
* @param {Object} [options] Options object
*/
forObject: function(obj, options) {
options || (options = { });
__convertPercentUnitsToValues(obj, options.coords, options.gradientUnits, {
// those values are to avoid errors. this function is uniquely used by
viewBoxWidth: 100,
viewBoxHeight: 100,
});
return new fabric.Gradient(options);
}
/* _FROM_SVG_END_ */
});

/**
Expand Down
6 changes: 0 additions & 6 deletions src/mixins/canvas_events.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,6 @@
if (this.getActiveObject()) {
this.discardActiveObject(e).requestRenderAll();
}
if (this.clipTo) {
fabric.util.clipContext(this, this.contextTop);
}
var pointer = this.getPointer(e);
this.freeDrawingBrush.onMouseDown(pointer, { e: e, pointer: pointer });
this._handleEvent(e, 'down');
Expand All @@ -624,9 +621,6 @@
* @param {Event} e Event object fired on mouseup
*/
_onMouseUpInDrawingMode: function(e) {
if (this.clipTo) {
this.contextTop.restore();
}
var pointer = this.getPointer(e);
this._isCurrentlyDrawing = this.freeDrawingBrush.onMouseUp({ e: e, pointer: pointer });
this._handleEvent(e, 'up');
Expand Down
19 changes: 0 additions & 19 deletions src/mixins/canvas_serialization.mixin.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.StaticCanvas.prototype */ {

/**
* Populates canvas with data from the specified dataless JSON.
* JSON format must conform to the one of {@link fabric.Canvas#toDatalessJSON}
* @deprecated since 1.2.2
* @param {String|Object} json JSON string or object
* @param {Function} callback Callback, invoked when json is parsed
* and corresponding objects (e.g: {@link fabric.Image})
* are initialized
* @param {Function} [reviver] Method for further parsing of JSON elements, called after each fabric object created.
* @return {fabric.Canvas} instance
* @chainable
* @tutorial {@link http://fabricjs.com/fabric-intro-part-3#deserialization}
*/
loadFromDatalessJSON: function (json, callback, reviver) {
return this.loadFromJSON(json, callback, reviver);
},

/**
* Populates canvas with data from the specified JSON.
* JSON format must conform to the one of {@link fabric.Canvas#toJSON}
Expand Down Expand Up @@ -231,7 +213,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
el.height = this.height;

var clone = new fabric.Canvas(el);
clone.clipTo = this.clipTo;
if (this.backgroundImage) {
clone.setBackgroundImage(this.backgroundImage.src, function() {
clone.renderAll();
Expand Down
10 changes: 1 addition & 9 deletions src/mixins/object.svg_export.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,7 @@
var transform = full ? this.calcTransformMatrix() : this.calcOwnMatrix(),
svgTransform = 'transform="' + fabric.util.matrixToSVG(transform);
return svgTransform +
(additionalTransform || '') + this.getSvgTransformMatrix() + '" ';
},

/**
* Returns transform-string for svg-export from the transform matrix of single elements
* @return {String}
*/
getSvgTransformMatrix: function() {
return this.transformMatrix ? ' ' + fabric.util.matrixToSVG(this.transformMatrix) : '';
(additionalTransform || '') + '" ';
},

_setSVGBg: function(textBgRects) {
Expand Down
16 changes: 4 additions & 12 deletions src/mixins/observable.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@

/**
* Observes specified event
* @deprecated `observe` deprecated since 0.8.34 (use `on` instead)
* @memberOf fabric.Observable
* @alias on
* @param {String|Object} eventName Event name (eg. 'after:render') or object with key/value pairs (eg. {'after:render': handler, 'selection:cleared': handler})
* @param {Function} handler Function that receives a notification when an event of the specified type occurs
* @return {Self} thisArg
* @chainable
*/
function observe(eventName, handler) {
function on(eventName, handler) {
if (!this.__eventListeners) {
this.__eventListeners = { };
}
Expand All @@ -50,15 +49,14 @@
/**
* Stops event observing for a particular event handler. Calling this method
* without arguments removes all handlers for all events
* @deprecated `stopObserving` deprecated since 0.8.34 (use `off` instead)
* @memberOf fabric.Observable
* @alias off
* @param {String|Object} eventName Event name (eg. 'after:render') or object with key/value pairs (eg. {'after:render': handler, 'selection:cleared': handler})
* @param {Function} handler Function to be deleted from EventListeners
* @return {Self} thisArg
* @chainable
*/
function stopObserving(eventName, handler) {
function off(eventName, handler) {
if (!this.__eventListeners) {
return this;
}
Expand All @@ -83,9 +81,7 @@

/**
* Fires event with an optional options object
* @deprecated `fire` deprecated since 1.0.7 (use `trigger` instead)
* @memberOf fabric.Observable
* @alias trigger
* @param {String} eventName Event name to fire
* @param {Object} [options] Options object
* @return {Self} thisArg
Expand Down Expand Up @@ -116,12 +112,8 @@
* @see {@link http://fabricjs.com/events|Events demo}
*/
fabric.Observable = {
observe: observe,
stopObserving: stopObserving,
fire: fire,

on: observe,
off: stopObserving,
trigger: fire
on: on,
off: off,
};
})();
22 changes: 1 addition & 21 deletions src/mixins/shared_methods.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,6 @@ fabric.CommonMethods = {
}
},

/**
* @private
* @param {Object} [options] Options object
*/
_initClipping: function(options) {
if (!options.clipTo || typeof options.clipTo !== 'string') {
return;
}

var functionBody = fabric.util.getFunctionBody(options.clipTo);
if (typeof functionBody !== 'undefined') {
this.clipTo = new Function('ctx', functionBody);
}
},

/**
* @private
*/
Expand All @@ -75,12 +60,7 @@ fabric.CommonMethods = {
this._setObject(key);
}
else {
if (typeof value === 'function' && key !== 'clipTo') {
this._set(key, value(this.get(key)));
}
else {
this._set(key, value);
}
this._set(key, value);
}
return this;
},
Expand Down
1 change: 0 additions & 1 deletion src/shapes/itext.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@
ctx.save();
ctx.transform(v[0], v[1], v[2], v[3], v[4], v[5]);
this.transform(ctx);
this.transformMatrix && ctx.transform.apply(ctx, this.transformMatrix);
this._clearTextArea(ctx);
skipRestore || ctx.restore();
},
Expand Down
Loading