mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Change straps.js to directly use initialize() as constructor function rather than redirecting calls to it.
Should yield some interesting performance improvements.
This commit is contained in:
parent
094e35f2e5
commit
369b329b23
14 changed files with 24 additions and 21 deletions
|
@ -252,16 +252,19 @@ var Base = this.Base = new function() { // Straps scope
|
|||
},
|
||||
|
||||
extend: function(src/* , ... */) {
|
||||
var ctor = function() {
|
||||
// Call the constructor function, if defined
|
||||
if (this.initialize)
|
||||
return this.initialize.apply(this, arguments);
|
||||
var ctor,
|
||||
base = this;
|
||||
// Look for an initialize function in all injection scopes and use
|
||||
// it as the actual constructor.
|
||||
for (var i = 0, l = arguments.length; i < l; i++)
|
||||
if (ctor = arguments[i].initialize)
|
||||
break;
|
||||
// If no initialize function is provided, create one that simply
|
||||
// calls the base constructor.
|
||||
ctor = ctor || function() {
|
||||
base.apply(this, arguments);
|
||||
};
|
||||
ctor.prototype = create(this.prototype);
|
||||
// Add a toString function that delegates to initialize if possible
|
||||
ctor.toString = function() {
|
||||
return (this.prototype.initialize || function() {}).toString();
|
||||
};
|
||||
// The new prototype extends the constructor on which extend is
|
||||
// called. Fix constructor.
|
||||
define(ctor.prototype, 'constructor',
|
||||
|
|
|
@ -89,7 +89,7 @@ var Group = this.Group = Item.extend(/** @lends Group# */{
|
|||
* });
|
||||
*/
|
||||
initialize: function(arg) {
|
||||
this.base();
|
||||
Item.call(this);
|
||||
// Allow Group to have children and named children
|
||||
this._children = [];
|
||||
this._namedChildren = {};
|
||||
|
|
|
@ -61,7 +61,7 @@ var Layer = this.Layer = Group.extend(/** @lends Layer# */{
|
|||
this._project = paper.project;
|
||||
// Push it onto project.layers and set index:
|
||||
this._index = this._project.layers.push(this) - 1;
|
||||
this.base.apply(this, arguments);
|
||||
Group.apply(this, arguments);
|
||||
this.activate();
|
||||
},
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ var PlacedSymbol = this.PlacedSymbol = Item.extend(/** @lends PlacedSymbol# */{
|
|||
// Support two forms of item initialization: Passing one object literal
|
||||
// describing all the different properties to be set, or a symbol (arg0)
|
||||
// and a point where it should be placed (arg1).
|
||||
this.base(arg1 !== undefined && Point.read(arguments, 1));
|
||||
Item.call(this, arg1 !== undefined && Point.read(arguments, 1));
|
||||
// If we can handle setting properties through object literal, we're all
|
||||
// set. Otherwise we need to set symbol.
|
||||
if (arg0 && !this._set(arg0))
|
||||
|
|
|
@ -76,7 +76,7 @@ var Raster = this.Raster = Item.extend(/** @lends Raster# */{
|
|||
// Support two forms of item initialization: Passing one object literal
|
||||
// describing all the different properties to be set, or an image
|
||||
// (object) and a point where it should be placed (point).
|
||||
this.base(position !== undefined && Point.read(arguments, 1));
|
||||
Item.call(this, position !== undefined && Point.read(arguments, 1));
|
||||
// If we can handle setting properties through object literal, we're all
|
||||
// set. Otherwise we need to check the type of object:
|
||||
if (object && !this._set(object)) {
|
||||
|
|
|
@ -22,7 +22,7 @@ var Shape = this.Shape = Item.extend(/** @lends Shape# */{
|
|||
_applyMatrix: false,
|
||||
|
||||
initialize: function(type, point, size) {
|
||||
this.base(point);
|
||||
Item.call(this, point);
|
||||
this._type = type;
|
||||
this._size = size;
|
||||
},
|
||||
|
|
|
@ -50,7 +50,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath#
|
|||
* compoundPath.children[1].position.x += 5;
|
||||
*/
|
||||
initialize: function(arg) {
|
||||
this.base();
|
||||
PathItem.call(this);
|
||||
// CompoundPath has children and supports named children.
|
||||
this._children = [];
|
||||
this._namedChildren = {};
|
||||
|
|
|
@ -70,7 +70,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
|||
initialize: function(arg) {
|
||||
this._closed = false;
|
||||
this._segments = [];
|
||||
this.base();
|
||||
Item.call(this);
|
||||
// arg can either be an object literal describing properties to be set
|
||||
// on the path, a list of segments to be set, or the first of multiple
|
||||
// arguments describing separate segments.
|
||||
|
|
|
@ -47,7 +47,7 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
|
|||
initialize: function(view) {
|
||||
// Activate straight away by passing true to base(), so paper.project is
|
||||
// set, as required by Layer and DoumentView constructors.
|
||||
this.base(true);
|
||||
PaperScopeItem.call(this, true);
|
||||
this.layers = [];
|
||||
this.symbols = [];
|
||||
this._currentStyle = new Style();
|
||||
|
|
|
@ -38,7 +38,7 @@ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
|
|||
// might be a properties object literal for #setPropeties() at the end.
|
||||
var hasProperties = arg && Base.isPlainObject(arg)
|
||||
&& arg.x === undefined && arg.y === undefined;
|
||||
this.base(hasProperties ? null : Point.read(arguments));
|
||||
Item.call(this, hasProperties ? null : Point.read(arguments));
|
||||
this._content = '';
|
||||
this._lines = [];
|
||||
if (hasProperties)
|
||||
|
|
|
@ -51,7 +51,7 @@ var Tool = this.Tool = PaperScopeItem.extend(/** @lends Tool# */{
|
|||
|
||||
// DOCS: rewrite Tool constructor explanation
|
||||
initialize: function(props) {
|
||||
this.base();
|
||||
PaperScopeItem.call(this);
|
||||
this._firstMove = true;
|
||||
this._count = 0;
|
||||
this._downCount = 0;
|
||||
|
|
|
@ -34,7 +34,7 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
|
|||
this._context = canvas.getContext('2d');
|
||||
// Have Item count installed mouse events.
|
||||
this._eventCounters = {};
|
||||
this.base(canvas);
|
||||
View.call(this, canvas);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
*/
|
||||
var KeyEvent = this.KeyEvent = Event.extend(/** @lends KeyEvent# */{
|
||||
initialize: function(down, key, character, event) {
|
||||
this.base(event);
|
||||
Event.call(this, event);
|
||||
this.type = down ? 'keydown' : 'keyup';
|
||||
this.key = key;
|
||||
this.character = character;
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
*/
|
||||
var MouseEvent = this.MouseEvent = Event.extend(/** @lends MouseEvent# */{
|
||||
initialize: function(type, event, point, target, delta) {
|
||||
this.base(event);
|
||||
Event.call(this, event);
|
||||
this.type = type;
|
||||
this.point = point;
|
||||
this.target = target;
|
||||
|
|
Loading…
Reference in a new issue