]> Lady’s Gitweb - Etiquette/commitdiff
Return this on Tag add/delete methods
authorLady <redacted>
Mon, 29 May 2023 07:44:00 +0000 (00:44 -0700)
committerLady <redacted>
Wed, 14 Jun 2023 02:07:48 +0000 (19:07 -0700)
model.js
model.test.js

index 76bf615bc2aaf4a5318af3cd75ec40bde4be7894..6963a16778601567b5d56bef31763af503eeeba1 100644 (file)
--- a/model.js
+++ b/model.js
@@ -385,7 +385,10 @@ class Tag {
     });
   }
 
-  /** Adds the provided label(s) to this `Tag` as alternate labels. */
+  /**
+   * Adds the provided label(s) to this `Tag` as alternate labels, then
+   * returns this `Tag`.
+   */
   addAltLabel(...labels) {
     const altLabels = this.#data.altLabel;
     let objectLabels = null; // initialized on first use
@@ -428,11 +431,12 @@ class Tag {
         altLabels.add(literal);
       }
     }
+    return this;
   }
 
   /**
    * Adds the provided tags to the list of tags that this `Tag` is
-   * narrower than.
+   * narrower than, then returns this `Tag`.
    *
    * Arguments may be string identifiers or objects with an
    * `.identifier` property.
@@ -474,9 +478,13 @@ class Tag {
         }
       }
     }
+    return this;
   }
 
-  /** Adds the provided label(s) to this `Tag` as hidden labels. */
+  /**
+   * Adds the provided label(s) to this `Tag` as hidden labels, then
+   * returns this `Tag`.
+   */
   addHiddenLabel(...labels) {
     const hiddenLabels = this.#data.hiddenLabel;
     let objectLabels = null; // initialized on first use
@@ -519,11 +527,12 @@ class Tag {
         hiddenLabels.add(literal);
       }
     }
+    return this;
   }
 
   /**
    * Adds the provided tags to the list of tags that this `Tag` is in
-   * canon with.
+   * canon with, then returns this `Tag`.
    *
    * Arguments may be string identifiers or objects with an
    * `.identifier` property.
@@ -584,11 +593,12 @@ class Tag {
         }
       }
     }
+    return this;
   }
 
   /**
    * Adds the provided tags to the list of tags that this `Tag`
-   * involves.
+   * involves, then returns this `Tag`.
    *
    * Arguments may be string identifiers or objects with an
    * `.identifier` property.
@@ -650,6 +660,7 @@ class Tag {
         }
       }
     }
+    return this;
   }
 
   /** Yields the alternative labels of this `Tag`. */
@@ -726,7 +737,7 @@ class Tag {
 
   /**
    * Removes the provided string label(s) from this `Tag` as alternate
-   * labels.
+   * labels, then returns this `Tag`.
    */
   deleteAltLabel(...labels) {
     const altLabels = this.#data.altLabel;
@@ -761,11 +772,12 @@ class Tag {
         altLabels.delete(literal);
       }
     }
+    return this;
   }
 
   /**
    * Removes the provided tags from the list of tags that this `Tag` is
-   * narrower than.
+   * narrower than, then returns this `Tag`.
    *
    * Arguments may be string identifiers or objects with an
    * `.identifier` property.
@@ -776,11 +788,12 @@ class Tag {
       // Iterate over the provided tags and delete them.
       broader.delete(toIdentifier($));
     }
+    return this;
   }
 
   /**
    * Removes the provided string label(s) from this `Tag` as hidden
-   * labels.
+   * labels, then returns this `Tag`.
    */
   deleteHiddenLabel(...labels) {
     const hiddenLabels = this.#data.hiddenLabel;
@@ -815,11 +828,12 @@ class Tag {
         hiddenLabels.delete(literal);
       }
     }
+    return this;
   }
 
   /**
    * Removes the provided tags from the list of tags that this `Tag` is
-   * in canon with.
+   * in canon with, then returns this `Tag`.
    *
    * Arguments may be string identifiers or objects with an
    * `.identifier` property.
@@ -830,11 +844,12 @@ class Tag {
       // Iterate over the provided tags and delete them.
       inCanon.delete(toIdentifier($));
     }
+    return this;
   }
 
   /**
    * Removes the provided tags from the list of tags that this `Tag`
-   * involves.
+   * involves, then returns this `Tag`.
    *
    * Arguments may be string identifiers or objects with an
    * `.identifier` property.
@@ -845,6 +860,7 @@ class Tag {
       // Iterate over the provided tags and delete them.
       involves.delete(toIdentifier($));
     }
+    return this;
   }
 
   /** Yields `Tag`s that are in canon of this `Tag`. */
index a648d4f736b8e6fb44dcb06c681c6bf739615a59..7190830c3a043dd200bfecf4ed7d68d924e6b32c 100644 (file)
@@ -306,6 +306,11 @@ describe("TagSystem", () => {
           ],
         );
       });
+
+      it("[[Call]] returns this", () => {
+        const tag = new Tag();
+        assertStrictEquals(tag.addAltLabel(), tag);
+      });
     });
 
     describe("::addBroaderTag", () => {
@@ -328,6 +333,11 @@ describe("TagSystem", () => {
         );
       });
 
+      it("[[Call]] returns this", () => {
+        const tag = new Tag();
+        assertStrictEquals(tag.addBroaderTag(), tag);
+      });
+
       it("[[Call]] throws when adding a non‐persisted tag", () => {
         const tag = new Tag();
         assertThrows(() => {
@@ -372,6 +382,11 @@ describe("TagSystem", () => {
           ],
         );
       });
+
+      it("[[Call]] returns this", () => {
+        const tag = new Tag();
+        assertStrictEquals(tag.addHiddenLabel(), tag);
+      });
     });
 
     describe("::addInCanonTag", () => {
@@ -394,6 +409,11 @@ describe("TagSystem", () => {
         );
       });
 
+      it("[[Call]] returns this", () => {
+        const tag = new Tag("EntityTag");
+        assertStrictEquals(tag.addInCanonTag(), tag);
+      });
+
       it("[[Call]] throws when this is not a tag which can be placed in canon", () => {
         assertThrows(() => {
           new Tag().addInCanonTag();
@@ -447,6 +467,11 @@ describe("TagSystem", () => {
         );
       });
 
+      it("[[Call]] returns this", () => {
+        const tag = new Tag("ConceptualTag");
+        assertStrictEquals(tag.addInvolvesTag(), tag);
+      });
+
       it("[[Call]] throws when this is not a conceptual tag", () => {
         assertThrows(() => {
           new Tag().addInvolvesTag();
@@ -547,6 +572,11 @@ describe("TagSystem", () => {
         );
         assertEquals([...tag.altLabels()], ["four"]);
       });
+
+      it("[[Call]] returns this", () => {
+        const tag = new Tag();
+        assertStrictEquals(tag.deleteAltLabel(), tag);
+      });
     });
 
     describe("::deleteBroaderTag", () => {
@@ -579,6 +609,11 @@ describe("TagSystem", () => {
           [broader2.identifier],
         );
       });
+
+      it("[[Call]] returns this", () => {
+        const tag = new Tag();
+        assertStrictEquals(tag.deleteBroaderTag(), tag);
+      });
     });
 
     describe("::deleteHiddenLabel", () => {
@@ -605,6 +640,11 @@ describe("TagSystem", () => {
         );
         assertEquals([...tag.hiddenLabels()], ["four"]);
       });
+
+      it("[[Call]] returns this", () => {
+        const tag = new Tag();
+        assertStrictEquals(tag.deleteHiddenLabel(), tag);
+      });
     });
 
     describe("::deleteInCanonTag", () => {
@@ -633,6 +673,11 @@ describe("TagSystem", () => {
           [canon2.identifier],
         );
       });
+
+      it("[[Call]] returns this", () => {
+        const tag = new Tag("EntityTag");
+        assertStrictEquals(tag.deleteInCanonTag(), tag);
+      });
     });
 
     describe("::deleteInvolvesTag", () => {
@@ -665,6 +710,11 @@ describe("TagSystem", () => {
           [involved2.identifier],
         );
       });
+
+      it("[[Call]] returns this", () => {
+        const tag = new Tag("ConceptualTag");
+        assertStrictEquals(tag.deleteInvolvesTag(), tag);
+      });
     });
 
     describe("::hasInCanonTags", () => {
This page took 0.034085 seconds and 4 git commands to generate.