]> Lady’s Gitweb - Etiquette/blobdiff - model.js
Add methods to get the system of a Tag
[Etiquette] / model.js
index d64f6c4218889f7cab3c60dbc215fec884fe6ead..7e0fefc9e5836bcd5b3080708111dd10894b45b4 100644 (file)
--- 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),
         );
       }
 
@@ -901,7 +913,7 @@ const {
        * of the `TagSystem` associated with this constructor.
        *
        * ※ If the I·R·I is not recognized, this function returns
-       * `null`.
+       * `undefined`.
        */
       fromIRI(iri) {
         const system = this.#system;
@@ -919,10 +931,12 @@ const {
           try {
             // Attempt to resolve the identifier.
             const instance = storage.get(identifier);
-            return Tag.getSystem(instance) == system ? instance : null;
+            return Tag.getSystem(instance) == system
+              ? instance
+              : undefined;
           } catch {
             // Do not throw for bad identifiers.
-            return null;
+            return undefined;
           }
         }
       }
@@ -933,13 +947,15 @@ const {
        * ☡ This function throws if the identifier is invalid.
        *
        * ※ If the identifier is valid but not recognized, this
-       * function returns `null`.
+       * function returns `undefined`.
        */
       fromIdentifier(identifier) {
         const system = this.#system;
         const storage = this.#storage;
         const instance = storage.get(identifier);
-        return Tag.getSystem(instance) == system ? instance : null;
+        return Tag.getSystem(instance) == system
+          ? instance
+          : undefined;
       }
 
       /**
@@ -949,7 +965,7 @@ const {
        * match the tagging entity of this constructor’s `TagSystem`.
        *
        * ※ If the specific component of the Tag U·R·I is not
-       * recognized, this function returns `null`.
+       * recognized, this function returns `undefined`.
        */
       fromTagURI(tagURI) {
         const system = this.#system;
@@ -967,10 +983,12 @@ const {
           try {
             // Attempt to resolve the identifier.
             const instance = storage.get(identifier);
-            return Tag.getSystem(instance) == system ? instance : null;
+            return Tag.getSystem(instance) == system
+              ? instance
+              : undefined;
           } catch {
             // Do not throw for bad identifiers.
-            return null;
+            return undefined;
           }
         }
       }
@@ -995,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.
This page took 0.02615 seconds and 4 git commands to generate.