chore(core): Made raise non-iterable
This commit is contained in:
parent
ffd7ecda59
commit
75f0e97c05
4 changed files with 15 additions and 21 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue