From: Lady Date: Tue, 20 Jun 2023 01:17:28 +0000 (-0700) Subject: Add methods to get the system of a Tag X-Git-Url: https://git.ladys.computer/Etiquette/commitdiff_plain/83cf1728db4305d5b40bdbccef92a9e01877489f?hp=6aa0118531463c0f1716b19013607658966a84cc Add methods to get the system of a Tag --- diff --git a/model.js b/model.js index cfd228d..7e0fefc 100644 --- a/model.js +++ b/model.js @@ -439,6 +439,9 @@ class Tag { * ※ This function can be used to check if the provided value has * private tag features. * + * ※ `Tag::system` is an overridable, publicly‐accessible means of + * accessing the system. + * * ※ This function is not exposed. */ static getSystem($) { @@ -489,6 +492,15 @@ class Tag { return this.#kind; } + /** + * Returns the `TagSystem` for this `Tag`. + * + * ※ Internally, `Tag.getSystem` is preferred. + */ + get system() { + return this.#system; + } + /** * Persist this `Tag` to storage and return an ActivityStreams * serialization of a Tag Activity representing any changes, or @@ -859,8 +871,8 @@ const { function Tag() { throw new TypeError("Tags must belong to a System."); }; - const { prototype: methods } = this; - delete methods.constructor; + const { prototype: staticFeatures } = this; + delete staticFeatures.constructor; Object.defineProperty(superclass, "prototype", { configurable: false, enumerable: false, @@ -869,7 +881,7 @@ const { }); Object.defineProperties( superclass, - Object.getOwnPropertyDescriptors(methods), + Object.getOwnPropertyDescriptors(staticFeatures), ); } @@ -1001,6 +1013,11 @@ const { } } + /** Returns the `TagSystem` for this `Tag` constructor. */ + get system() { + return this.#system; + } + /** * Returns a new `Tag` constructed from the provided data and * with the provided identifier. diff --git a/model.test.js b/model.test.js index ed1430e..4396d37 100644 --- a/model.test.js +++ b/model.test.js @@ -280,6 +280,12 @@ describe("TagSystem", () => { }); }); + describe(".system", () => { + it("[[Call]] returns the `TagSystem`", () => { + assertEquals(Tag.system, system); + }); + }); + // `.[Storage.toInstance]` is tested by `.fromIdentifier`. describe("::addAltLabel", () => { @@ -939,6 +945,12 @@ describe("TagSystem", () => { }); }); + describe("::system", () => { + it("[[Get]] returns the tag system", () => { + assertStrictEquals(new Tag().system, system); + }); + }); + // `::tagURI` is tested by a `.fromTagURI`. describe("::taggingEntity", () => {