From 0d0784bb95ae5b46b1da689e7e35579263653e84 Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Thu, 16 Aug 2018 12:09:57 +0200 Subject: [PATCH] :sparkles: Switched Pattern.inScope() to Pattern.needs() --- src/pattern.js | 18 +++++++++--------- src/svg.js | 2 +- tests/pattern.test.js | 24 ++++++++++++------------ 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/pattern.js b/src/pattern.js index 84b421361a5..df507eef899 100644 --- a/src/pattern.js +++ b/src/pattern.js @@ -248,7 +248,7 @@ Pattern.prototype.pack = function() { let part = this.parts[key]; // Avoid multiple render calls to cause stacking of transforms part.attributes.set("transform", ""); - if (part.render && this.inScope(key)) { + if (part.render && this.needs(key)) { part.stack(); bins.push({ id: key, @@ -269,18 +269,18 @@ Pattern.prototype.pack = function() { return this; }; -/** Determines whether a part is in scope - * Scope depends on the 'only' setting people can pass - * with the name of a part, or an array of parts - * The absence of only means all parts +/** Determines whether a part is needed + * This depends on the 'only' setting. People can pass + * the name of a part, or an array of parts + * The absence of only means all parts are needed. * - * If partName is an array of names, any name being in - * scope will cause this to return true + * If partName is an array of names, any name needed + * will cause this to return true */ -Pattern.prototype.inScope = function(partName) { +Pattern.prototype.needs = function(partName) { if (typeof partName !== "string") { for (let part of partName) { - if (this.inScope(part)) return true; + if (this.needs(part)) return true; } return false; } diff --git a/src/svg.js b/src/svg.js index a879ae30244..c093ae87ba5 100644 --- a/src/svg.js +++ b/src/svg.js @@ -61,7 +61,7 @@ Svg.prototype.render = function(pattern) { this.svg += this.openGroup("draftContainer"); for (let partId in pattern.parts) { let part = pattern.parts[partId]; - if (part.render && pattern.inScope(partId)) { + if (part.render && pattern.needs(partId)) { this.svg += this.openGroup(this.getUid(), part.attributes); this.svg += this.renderPart(part); this.svg += this.closeGroup(); diff --git a/tests/pattern.test.js b/tests/pattern.test.js index 672bcff64db..c137985f45b 100644 --- a/tests/pattern.test.js +++ b/tests/pattern.test.js @@ -139,26 +139,26 @@ it("Should register a hook from a plugin", () => { expect(count).to.equal(1); }); -it("Should check whether a part is in scope", () => { +it("Should check whether a part is needed", () => { let pattern = new freesewing.Pattern(); pattern.settings.only = "test"; - expect(pattern.inScope("test")).to.equal(true); - expect(pattern.inScope("mist")).to.equal(false); + expect(pattern.needs("test")).to.equal(true); + expect(pattern.needs("mist")).to.equal(false); }); -it("Should check whether an array of parts is in scope", () => { +it("Should check whether an array of parts is needed", () => { let pattern = new freesewing.Pattern(); pattern.settings.only = "test"; - expect(pattern.inScope(["foo", "bar", "test"])).to.equal(true); - expect(pattern.inScope(["foo", "bar", "mist"])).to.equal(false); + expect(pattern.needs(["foo", "bar", "test"])).to.equal(true); + expect(pattern.needs(["foo", "bar", "mist"])).to.equal(false); }); -it("Should check whether a parts is in a scope array", () => { +it("Should check whether a parts is needed with array", () => { let pattern = new freesewing.Pattern(); pattern.settings.only = ["test", "foo", "bar"]; - expect(pattern.inScope("foo")).to.equal(true); - expect(pattern.inScope(["bar"])).to.equal(true); - expect(pattern.inScope(["mest", "foo"])).to.equal(true); - expect(pattern.inScope(["mist", "hugs"])).to.equal(false); - expect(pattern.inScope("jugs")).to.equal(false); + expect(pattern.needs("foo")).to.equal(true); + expect(pattern.needs(["bar"])).to.equal(true); + expect(pattern.needs(["mest", "foo"])).to.equal(true); + expect(pattern.needs(["mist", "hugs"])).to.equal(false); + expect(pattern.needs("jugs")).to.equal(false); });