Parcourir la source

Docs: introduce TrackerResult.of()

customisations
alemart il y a 3 mois
Parent
révision
a4c17b3fd6
2 fichiers modifiés avec 36 ajouts et 2 suppressions
  1. 35
    1
      docs/api/tracker-result.md
  2. 1
    1
      docs/api/tracker.md

+ 35
- 1
docs/api/tracker-result.md Voir le fichier

@@ -14,4 +14,38 @@ A reference to the [tracker](tracker.md) that generated this result.
14 14
 
15 15
 `result.trackables: Trackable[], read-only`
16 16
 
17
-An array of zero or more [trackables](trackable.md).
17
+An array of zero or more [trackables](trackable.md).
18
+
19
+## Methods
20
+
21
+### of
22
+
23
+`result.of(trackerType: string): boolean`
24
+
25
+Checks if `this` result was generated by tracker of a certain `trackerType`. This is a convenient type guard for TypeScript users. See also: [Tracker.is](./tracker.md#is).
26
+
27
+*Since:* 0.4.4
28
+
29
+**Returns**
30
+
31
+The same as `tracker.is(trackerType)`.
32
+
33
+**Example**
34
+
35
+```ts
36
+let result: TrackerResult;
37
+
38
+// ...
39
+
40
+if(result.of('image-tracker')) {
41
+    // result is inferred to be an ImageTrackerResult
42
+    // ...
43
+}
44
+else if(result.of('pointer-tracker')) {
45
+    // result is inferred to be a PointerTrackerResult
46
+    // ...
47
+}
48
+else {
49
+    // ...
50
+}
51
+```

+ 1
- 1
docs/api/tracker.md Voir le fichier

@@ -20,7 +20,7 @@ A string representing the type of the tracker.
20 20
 
21 21
 `tracker.is(type: string): boolean`
22 22
 
23
-Checks if `this` tracker is of a certain `type`. This works as a convenient type-narrowing method for TypeScript users.
23
+Checks if `this` tracker is of a certain `type`. This is a convenient type guard for TypeScript users. See also: [TrackerResult.of](./tracker-result.md#of).
24 24
 
25 25
 *Since:* 0.4.4
26 26
 

Chargement…
Annuler
Enregistrer