1
0
Fork 0
freesewing/packages/core/src/snippet.js
2019-08-03 15:03:33 +02:00

27 lines
641 B
JavaScript

import Attributes from './attributes'
function Snippet(def, anchor) {
this.def = def
this.anchor = anchor
this.attributes = new Attributes()
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)
else this.attributes.add(name, value)
return this
}
/** Returns a deep copy of this */
Snippet.prototype.clone = function() {
let clone = new Snippet(this.def, this.anchor.clone())
clone.attributes = this.attributes.clone()
return clone
}
export default Snippet