1
0
Fork 0
freesewing/packages/core/src/snippet.js

28 lines
655 B
JavaScript
Raw Normal View History

import Attributes from "./attributes";
2018-07-23 11:12:06 +00:00
2018-08-17 20:24:10 +02:00
function Snippet(def, anchor) {
2018-07-23 11:12:06 +00:00
this.def = def;
this.anchor = anchor;
this.attributes = new Attributes();
2018-07-23 11:12:06 +00:00
return this;
}
2018-08-17 20:24:10 +02:00
/** 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;
};
2018-08-03 14:20:28 +02:00
/** Returns a deep copy of this */
Snippet.prototype.clone = function() {
2018-08-17 20:24:10 +02:00
let clone = new Snippet(this.def, this.anchor.clone());
2018-08-03 14:20:28 +02:00
clone.attributes = this.attributes.clone();
return clone;
};
export default Snippet;