1
0
Fork 0

chore(core): Made raise non-iterable

This commit is contained in:
Joost De Cock 2020-07-23 10:26:04 +02:00
parent ffd7ecda59
commit 75f0e97c05
4 changed files with 15 additions and 21 deletions

View file

@ -199,20 +199,20 @@ Part.prototype.shorthand = function () {
// Wrap the Point constructor so objects can raise events // Wrap the Point constructor so objects can raise events
shorthand.Point = function (x, y) { shorthand.Point = function (x, y) {
Point.apply(this, [x, y, true]) 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) shorthand.Point.prototype = Object.create(Point.prototype)
// Wrap the Path constructor so objects can raise events // Wrap the Path constructor so objects can raise events
shorthand.Path = function () { shorthand.Path = function () {
Path.apply(this, [true]) Path.apply(this, [true])
this.raise = self.context.raise Object.defineProperty(this, 'raise', { value: self.context.raise })
} }
shorthand.Path.prototype = Object.create(Path.prototype) shorthand.Path.prototype = Object.create(Path.prototype)
// Wrap the Snippet constructor so objects can raise events // Wrap the Snippet constructor so objects can raise events
shorthand.Snippet = function (def, anchor) { shorthand.Snippet = function (def, anchor) {
Snippet.apply(this, [def, anchor, true]) Snippet.apply(this, [def, anchor, true])
Snippet.apply(this, arguments) Snippet.apply(this, arguments)
shorthand.raise = self.context.raise Object.defineProperty(this, 'raise', { value: self.context.raise })
} }
shorthand.Snippet.prototype = Object.create(Snippet.prototype) shorthand.Snippet.prototype = Object.create(Snippet.prototype)

View file

@ -12,18 +12,17 @@ import {
} from './utils' } from './utils'
function Path(debug = false) { function Path(debug = false) {
this.debug = debug
this.render = true this.render = true
this.topLeft = false this.topLeft = false
this.bottomRight = false this.bottomRight = false
this.attributes = new Attributes() this.attributes = new Attributes()
this.ops = [] this.ops = []
Object.defineProperty(this, 'debug', { value: debug })
} }
/** Adds the raise method for a path not created through the proxy **/ /** Adds the raise method for a path not created through the proxy **/
Path.prototype.withRaise = function (raise = false) { Path.prototype.withRaise = function (raise = false) {
if (raise) this.raise = raise if (raise) Object.defineProperty(this, 'raise', { value: raise })
else this.raise = () => null
return this return this
} }

View file

@ -2,20 +2,15 @@ import Attributes from './attributes'
import { round } from './utils' import { round } from './utils'
function Point(x, y, debug = false) { 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.x = round(x)
this.y = round(y) this.y = round(y)
this.attributes = new Attributes() this.attributes = new Attributes()
Object.defineProperty(this, 'debug', { value: debug })
} }
/** Adds the raise method for a path not created through the proxy **/ /** Adds the raise method for a path not created through the proxy **/
Point.prototype.withRaise = function (raise = false) { Point.prototype.withRaise = function (raise = false) {
if (raise) this.raise = raise if (raise) Object.defineProperty(this, 'raise', { value: raise })
else this.raise = () => null
return this return this
} }

View file

@ -2,20 +2,20 @@ import Attributes from './attributes'
import Point from './point' import Point from './point'
function Snippet(def, anchor, debug = false) { 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.def = def
this.anchor = anchor this.anchor = anchor
this.attributes = new Attributes() this.attributes = new Attributes()
Object.defineProperty(this, 'debug', { value: debug })
return this 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 */ /** Adds an attribute. This is here to make this call chainable in assignment */
Snippet.prototype.attr = function (name, value, overwrite = false) { Snippet.prototype.attr = function (name, value, overwrite = false) {
if (overwrite) this.attributes.set(name, value) 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 */ /** Returns a deep copy of this */
Snippet.prototype.clone = function () { 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.attributes = this.attributes.clone()
clone.raise = this.raise clone.raise = this.raise