-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.d.ts
102 lines (79 loc) · 2.06 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
export default class Cycled<T> extends Array<T> {
/**
Get or set the current index.
*/
index: number;
/**
Initiates an array subclass with the methods documented below.
Since it's an array, you can use all the normal array methods on it.
The instance is an iterable that will cycle through the array.
It will cycle through the number of elements equaling the length of the array from the current index.
@example
```
import Cycled from 'cycled';
const numberCycle = new Cycled([1, 2, 3, 4, 5]);
console.log(...numberCycle);
//=> 1 2 3 4 5
class TabComponent {
#activeView;
#views;
constructor(views) {
this.#activeView = views[0];
this.#views = new Cycled(views);
}
setActiveView(view) {
this.#activeView = view;
this.#views.index = this.#views.indexOf(view);
}
nextView() {
setActiveView(this.#views.next());
}
previousView() {
setActiveView(this.#views.previous());
}
}
const tabs = new TabComponent([
'Homepage',
'Blog',
'Projects',
'Contact'
]);
// …
nextButton.addEventListener('click', () => {
tabs.nextView();
});
```
*/
constructor(elements: readonly T[]);
/**
Returns the current item.
*/
current(): T;
/**
Returns the next item.
*/
next(): T;
/**
Returns the previous item.
*/
previous(): T;
/**
Returns the item by going the given amount of `steps` through the array. For example, calling `step(2)` is like calling `next()` twice.
You go backward by specifying a negative number.
*/
step(steps: number): T;
/**
Returns the item that is located in the given amount of `steps` through the array. For example, calling `peek(2)` would get the item 2 items after the current one.
You go backward by specifying a negative number.
This method is similar to `.step()` but without changing the current item.
*/
peek(steps: number): T;
/**
Returns an iterable that will cycle through the array indefinitely.
*/
indefinitely(): IterableIterator<T>;
/**
Returns an iterable that will cycle through the array backward indefinitely.
*/
indefinitelyReversed(): IterableIterator<T>;
}