1
0
Fork 0

wip: Pass parts to design constructor as array

Since the part name needs to be set in the part, this makes
it more clear as there's no key associated with the part.
This commit is contained in:
joostdecock 2022-08-14 18:16:15 +02:00
parent 2b254c721d
commit 7f684d8c17
3 changed files with 11 additions and 7 deletions

View file

@ -10,8 +10,13 @@ export default function Design(config, plugins = false, conditionalPlugins = fal
if (!config.options) config.options = {}
if (!config.measurements) config.measurements = []
if (!config.optionalMeasurements) config.optionalMeasurements = []
if (config.parts) {
for (const partName in config.parts) config = addPartConfig(config.parts[partName], config)
if (Array.isArray(config.parts)) {
const parts = {}
for (const part of config.parts) {
parts[part.name] = part
config = addPartConfig(parts[part.name], config)
}
config.parts = parts
}
// Ensure all options have a hide() method

View file

@ -758,7 +758,7 @@ Pattern.prototype.resolveDependencies = function (graph = this.dependencies) {
// Include parts outside the dependency graph
if (Array.isArray(this.config.parts)) {
for (let part of this.config.parts) {
if (typeof this.dependencies[part] === 'undefined') this.dependencies[part] = []
if (typeof part === 'string' && typeof this.dependencies[part] === 'undefined') this.dependencies[part] = []
}
}

View file

@ -1,6 +1,5 @@
let expect = require("chai").expect;
let freesewing = require("../dist/index.js");
/*
it("Pattern constructor should initialize object", () => {
let pattern = new freesewing.Pattern({
foo: "bar",
@ -783,7 +782,7 @@ it("Design constructor should resolve nested injections (2022)", () => {
}
}
const Design = new freesewing.Design({ parts: { partC } });
const Design = new freesewing.Design({ parts: [ partC ] });
const pattern = new Design().addPart(partR).draft()
// Measurements
expect(pattern.config.measurements.length).to.equal(4)
@ -878,7 +877,7 @@ it("Design constructor should resolve nested injections (2022)", () => {
expect(pattern.parts.partR.paths.r.ops[1].to.x).to.equal(44)
expect(pattern.parts.partR.paths.r.ops[1].to.y).to.equal(44)
})
*/
it("Design constructor should resolve nested dependencies (2022)", () => {
const partA = {
name: "partA",
@ -935,7 +934,7 @@ it("Design constructor should resolve nested dependencies (2022)", () => {
return part
}
}
const Design = new freesewing.Design({ parts: { partD } });
const Design = new freesewing.Design({ parts: [ partD ] });
const pattern = new Design().draft()
// Measurements
expect(pattern.config.measurements.length).to.equal(4)