Przeglądaj źródła

Docs: introduce TrackerResult.of()

customisations
alemart 3 miesięcy temu
rodzic
commit
a4c17b3fd6
2 zmienionych plików z 36 dodań i 2 usunięć
  1. 35
    1
      docs/api/tracker-result.md
  2. 1
    1
      docs/api/tracker.md

+ 35
- 1
docs/api/tracker-result.md Wyświetl plik

14
 
14
 
15
 `result.trackables: Trackable[], read-only`
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 Wyświetl plik

20
 
20
 
21
 `tracker.is(type: string): boolean`
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
 *Since:* 0.4.4
25
 *Since:* 0.4.4
26
 
26
 

Ładowanie…
Anuluj
Zapisz