Skip to content

Commit

Permalink
Added deprecate utility function, and re-introduced deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lannymcnie committed Jun 29, 2017
1 parent bcba2b0 commit e174f21
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 5 deletions.
1 change: 1 addition & 0 deletions build/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"../src/createjs/utils/promote.js",
"../src/createjs/utils/indexOf.js",
"../src/easeljs/utils/UID.js",
"../src/createjs/utils/deprecate.js",
"../src/createjs/events/Event.js",
"../src/createjs/events/EventDispatcher.js",
"../src/createjs/utils/Ticker.js",
Expand Down
8 changes: 8 additions & 0 deletions src/createjs/utils/Ticker.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ this.createjs = this.createjs||{};
if (!Ticker._inited) { return; }
Ticker._setupTick();
};
// Ticker.setInterval is @deprecated. Remove for 1.1+
Ticker.setInterval = createjs.deprecate(Ticker._setInterval, "Ticker.setInterval");

/**
* Use the {{#crossLink "Ticker/interval:property"}}{{/crossLink}} property instead.
Expand All @@ -327,6 +329,8 @@ this.createjs = this.createjs||{};
Ticker._getInterval = function() {
return Ticker._interval;
};
// Ticker.getInterval is @deprecated. Remove for 1.1+
Ticker.getInterval = createjs.deprecate(Ticker._getInterval, "Ticker.getInterval");

/**
* Use the {{#crossLink "Ticker/framerate:property"}}{{/crossLink}} property instead.
Expand All @@ -338,6 +342,8 @@ this.createjs = this.createjs||{};
Ticker._setFPS = function(value) {
Ticker._setInterval(1000/value);
};
// Ticker.setFPS is @deprecated. Remove for 1.1+
Ticker.setFPS = createjs.deprecate(Ticker._setFPS, "Ticker.setFPS");

/**
* Use the {{#crossLink "Ticker/framerate:property"}}{{/crossLink}} property instead.
Expand All @@ -349,6 +355,8 @@ this.createjs = this.createjs||{};
Ticker._getFPS = function() {
return 1000/Ticker._interval;
};
// Ticker.getFPS is @deprecated. Remove for 1.1+
Ticker.getFPS = createjs.deprecate(Ticker._getFPS, "Ticker.getFPS");

/**
* Indicates the target time (in milliseconds) between ticks. Default is 50 (20 FPS).
Expand Down
69 changes: 69 additions & 0 deletions src/createjs/utils/deprecate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* extend
* Visit http://createjs.com/ for documentation, updates and examples.
*
* Copyright (c) 2010 gskinner.com, inc.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

/**
* @module CreateJS
*/

// namespace:
this.createjs = this.createjs||{};

/**
* @class Utility Methods
*/

/**
* Wraps deprecated methods so they still be used, but throw warnings to developers.
*
* obj.deprecatedMethod = createjs.deprecate("Old Method Name", obj._fallbackMethod);
*
* The recommended approach for deprecated properties is:
*
* try {
* Obj ect.defineProperties(object, {
* readyOnlyProp: { get: createjs.deprecate("readOnlyProp", function() { return this.alternateProp; }) },
* readWriteProp: {
* get: createjs.deprecate("readOnlyProp", function() { return this.alternateProp; }),
* set: createjs.deprecate("readOnlyProp", function(val) { this.alternateProp = val; })
* });
* } catch (e) {}
*
* @method deprecate
* @param {Function} [fallbackMethod=null] A method to call when the deprecated method is used. See the example for how
* @param {String} [name=null] The name of the method or property to display in the console warning.
* to deprecate properties.
* @return {Function} If a fallbackMethod is supplied, returns a closure that will call the fallback method after
* logging the warning in the console.
*/
createjs.deprecate = function(fallbackMethod, name) {
"use strict";
return function() {
console && (console.warn || console.log)("Deprecated property or method '"+name+"'. See docs for info.");
return fallbackMethod && fallbackMethod.apply(this, arguments);
}
};
8 changes: 5 additions & 3 deletions src/easeljs/display/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ this.createjs = this.createjs||{};
// getter / setters:
/**
* Use the {{#crossLink "Container/numChildren:property"}}{{/crossLink}} property instead.
* @method getNumChildren
* @method _getNumChildren
* @protected
* @return {Number}
**/
p.getNumChildren = function() {
p._getNumChildren = function() {
return this.children.length;
};
// Container.getNumChildren is @deprecated. Remove for 1.1+
p.getNumChildren = createjs.deprecate(p._getNumChildren, "Container.getNumChildren");

/**
* Returns the number of children in the container.
Expand All @@ -112,7 +114,7 @@ this.createjs = this.createjs||{};
**/
try {
Object.defineProperties(p, {
numChildren: { get: p.getNumChildren }
numChildren: { get: p._getNumChildren }
});
} catch (e) {}

Expand Down
2 changes: 2 additions & 0 deletions src/easeljs/display/DisplayObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ this.createjs = this.createjs||{};
if (o instanceof _Stage) { return o; }
return null;
};
// DisplayObject.getStage is @deprecated. Remove for 1.1+
p.getStage = createjs.deprecate(p._getStage, "DisplayObject.getStage");

/**
* Returns the Stage instance that this display object will be rendered on, or null if it has not been added to one.
Expand Down
2 changes: 2 additions & 0 deletions src/easeljs/display/Graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ this.createjs = this.createjs||{};
this._updateInstructions();
return this._instructions;
};
// Graphics.getInstructions is @deprecated. Remove for 1.1+
p.getInstructions = createjs.deprecate(p._getInstructions, "Graphics.getInstructions");

/**
* Returns the graphics instructions array. Each entry is a graphics command object (ex. Graphics.Fill, Graphics.Rect)
Expand Down
10 changes: 8 additions & 2 deletions src/easeljs/display/MovieClip.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ this.createjs = this.createjs||{};
p._getLabels = function() {
return this.timeline.getLabels();
};

// MovieClip.getLabels is @deprecated. Remove for 1.1+
p.getLabels = createjs.deprecate(p._getLabels, "MovieClip.getLabels");

/**
* Use the {{#crossLink "MovieClip/currentLabel:property"}}{{/crossLink}} property instead.
* @method _getCurrentLabel
Expand All @@ -347,7 +349,9 @@ this.createjs = this.createjs||{};
p._getCurrentLabel = function() {
return this.timeline.currentLabel;
};

// MovieClip.getCurrentLabel is @deprecated. Remove for 1.1+
p.getCurrentLabel = createjs.deprecate(p._getCurrentLabel, "MovieClip.getCurrentLabel");

/**
* Use the {{#crossLink "MovieClip/duration:property"}}{{/crossLink}} property instead.
* @method _getDuration
Expand All @@ -357,6 +361,8 @@ this.createjs = this.createjs||{};
p._getDuration = function() {
return this.timeline.duration;
};
// MovieClip.getDuration is @deprecated. Remove for 1.1+
p.getDuration = createjs.deprecate(p._getDuration, "MovieClip.getDuration");

/**
* Returns an array of objects with label and position (aka frame) properties, sorted by position.
Expand Down
2 changes: 2 additions & 0 deletions src/easeljs/display/SpriteSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ this.createjs = this.createjs||{};
p._getAnimations = function() {
return this._animations.slice();
};
// SpriteSheet.getAnimations is @deprecated. Remove for 1.1+
p.getAnimations = createjs.deprecate(p._getAnimations, "SpriteSheet.getAnimations");

/**
* Returns an array of all available animation names available on this sprite sheet as strings.
Expand Down
5 changes: 5 additions & 0 deletions src/easeljs/ui/ButtonHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ this.createjs = this.createjs||{};
if (o.__reset) { o._reset = o.__reset; delete(o.__reset); }
}
};
// ButtonHelper.setEnabled is @deprecated. Remove for 1.1+
p.setEnabled = createjs.deprecate(p._setEnabled, "ButtonHelper.setEnabled");

/**
* Use the {{#crossLink "ButtonHelper/enabled:property"}}{{/crossLink}} property instead.
* @method getEnabled
Expand All @@ -187,6 +190,8 @@ this.createjs = this.createjs||{};
p._getEnabled = function() {
return this._enabled;
};
// ButtonHelper.getEnabled is @deprecated. Remove for 1.1+
p.getEnabled = createjs.deprecate(p._getEnabled, "ButtonHelper.getEnabled");

/**
* Enables or disables the button functionality on the target.
Expand Down
7 changes: 7 additions & 0 deletions src/easeljs/utils/SpriteSheetUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ this.createjs = this.createjs||{};
img.src = canvas.toDataURL("image/png");
return img;
};

// SpriteSheetUtils.addFlippedFrames is @deprecated. Remove for 1.1+
SpriteSheetUtils.addFlippedFrames = createjs.deprecate(null, "SpriteSheetUtils.addFlippedFrames");

// SpriteSheetUtils.addFlippedFrames is @deprecated. Remove for 1.1+
SpriteSheetUtils.mergeAlpha = createjs.deprecate(null, "SpriteSheetUtils.mergeAlpha");


// private static methods:
SpriteSheetUtils._flip = function(spriteSheet, count, h, v) {
Expand Down

0 comments on commit e174f21

Please sign in to comment.