diff --git a/packages/core/src/part.js b/packages/core/src/part.js index 730c73763b3..abb68590e4f 100644 --- a/packages/core/src/part.js +++ b/packages/core/src/part.js @@ -199,20 +199,20 @@ Part.prototype.shorthand = function () { // Wrap the Point constructor so objects can raise events shorthand.Point = function (x, y) { Point.apply(this, [x, y, true]) - this.raise = self.context.raise + Object.defineProperty(this, 'raise', { value: self.context.raise }) } shorthand.Point.prototype = Object.create(Point.prototype) // Wrap the Path constructor so objects can raise events shorthand.Path = function () { Path.apply(this, [true]) - this.raise = self.context.raise + Object.defineProperty(this, 'raise', { value: self.context.raise }) } shorthand.Path.prototype = Object.create(Path.prototype) // Wrap the Snippet constructor so objects can raise events shorthand.Snippet = function (def, anchor) { Snippet.apply(this, [def, anchor, true]) Snippet.apply(this, arguments) - shorthand.raise = self.context.raise + Object.defineProperty(this, 'raise', { value: self.context.raise }) } shorthand.Snippet.prototype = Object.create(Snippet.prototype) diff --git a/packages/core/src/path.js b/packages/core/src/path.js index b9f351df7cc..3cf59ef0a70 100644 --- a/packages/core/src/path.js +++ b/packages/core/src/path.js @@ -12,18 +12,17 @@ import { } from './utils' function Path(debug = false) { - this.debug = debug this.render = true this.topLeft = false this.bottomRight = false this.attributes = new Attributes() this.ops = [] + Object.defineProperty(this, 'debug', { value: debug }) } /** Adds the raise method for a path not created through the proxy **/ Path.prototype.withRaise = function (raise = false) { - if (raise) this.raise = raise - else this.raise = () => null + if (raise) Object.defineProperty(this, 'raise', { value: raise }) return this } diff --git a/packages/core/src/point.js b/packages/core/src/point.js index 566848b5eea..bbcbeccc196 100644 --- a/packages/core/src/point.js +++ b/packages/core/src/point.js @@ -2,20 +2,15 @@ import Attributes from './attributes' import { round } from './utils' function Point(x, y, debug = false) { - this.debug = debug - if (this.debug) { - if (typeof x !== 'number') raise.warning('Called `new Point(x,y)` but `x` is not a number') - if (typeof y !== 'number') raise.warning('Called `new Point(x,y)` but `y` is not a number') - } this.x = round(x) this.y = round(y) this.attributes = new Attributes() + Object.defineProperty(this, 'debug', { value: debug }) } /** Adds the raise method for a path not created through the proxy **/ Point.prototype.withRaise = function (raise = false) { - if (raise) this.raise = raise - else this.raise = () => null + if (raise) Object.defineProperty(this, 'raise', { value: raise }) return this } diff --git a/packages/core/src/snippet.js b/packages/core/src/snippet.js index c61f9e3b8bb..8e04e764c0d 100644 --- a/packages/core/src/snippet.js +++ b/packages/core/src/snippet.js @@ -2,20 +2,20 @@ import Attributes from './attributes' import Point from './point' function Snippet(def, anchor, debug = false) { - this.debug = debug - if (this.debug) { - if (typeof def !== 'string') - raise.warning('Called `new Snippet(def, anchor)` but `def` is not a string') - if (anchor instanceof Point !== true) - raise.warning('Called `new Snippet(dev, anchor)` but `anchor` is not a `Point` object') - } this.def = def this.anchor = anchor this.attributes = new Attributes() + Object.defineProperty(this, 'debug', { value: debug }) return this } +/** Adds the raise method for a snippet not created through the proxy **/ +Snippet.prototype.withRaise = function (raise = false) { + if (raise) Object.defineProperty(this, 'raise', { value: raise }) + + return this +} /** Adds an attribute. This is here to make this call chainable in assignment */ Snippet.prototype.attr = function (name, value, overwrite = false) { if (overwrite) this.attributes.set(name, value) @@ -26,7 +26,7 @@ Snippet.prototype.attr = function (name, value, overwrite = false) { /** Returns a deep copy of this */ Snippet.prototype.clone = function () { - let clone = new Snippet(this.def, this.anchor.clone()) + let clone = new Snippet(this.def, this.anchor.clone()).withRaise(this.raise) clone.attributes = this.attributes.clone() clone.raise = this.raise