@operato/utils 2.0.0-alpha.0 → 2.0.0-alpha.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/src/adjust-list-param.d.ts +14 -0
- package/dist/src/adjust-list-param.js +8 -0
- package/dist/src/adjust-list-param.js.map +1 -1
- package/dist/src/async-lock.d.ts +13 -0
- package/dist/src/async-lock.js +13 -0
- package/dist/src/async-lock.js.map +1 -1
- package/dist/src/clipboard.d.ts +7 -0
- package/dist/src/clipboard.js +7 -0
- package/dist/src/clipboard.js.map +1 -1
- package/dist/src/closest-element.d.ts +7 -0
- package/dist/src/closest-element.js +7 -0
- package/dist/src/closest-element.js.map +1 -1
- package/dist/src/context-path.d.ts +15 -0
- package/dist/src/context-path.js +20 -0
- package/dist/src/context-path.js.map +1 -1
- package/dist/src/cookie.d.ts +18 -0
- package/dist/src/cookie.js +18 -0
- package/dist/src/cookie.js.map +1 -1
- package/dist/src/detect-overflow.d.ts +6 -0
- package/dist/src/detect-overflow.js +6 -0
- package/dist/src/detect-overflow.js.map +1 -1
- package/dist/src/format.d.ts +12 -0
- package/dist/src/format.js +12 -0
- package/dist/src/format.js.map +1 -1
- package/dist/src/logger.d.ts +15 -0
- package/dist/src/logger.js +15 -3
- package/dist/src/logger.js.map +1 -1
- package/dist/src/mixins/infinite-scrollable.d.ts +24 -0
- package/dist/src/mixins/infinite-scrollable.js +24 -0
- package/dist/src/mixins/infinite-scrollable.js.map +1 -1
- package/dist/src/os.d.ts +4 -0
- package/dist/src/os.js +4 -0
- package/dist/src/os.js.map +1 -1
- package/dist/src/password-pattern.d.ts +15 -0
- package/dist/src/password-pattern.js +15 -0
- package/dist/src/password-pattern.js.map +1 -1
- package/dist/src/stringify-bignum.d.ts +11 -0
- package/dist/src/stringify-bignum.js +11 -0
- package/dist/src/stringify-bignum.js.map +1 -1
- package/dist/src/timecapsule/snapshot-taker.d.ts +31 -0
- package/dist/src/timecapsule/snapshot-taker.js +36 -3
- package/dist/src/timecapsule/snapshot-taker.js.map +1 -1
- package/dist/src/timecapsule/timecapsule.d.ts +50 -0
- package/dist/src/timecapsule/timecapsule.js +50 -3
- package/dist/src/timecapsule/timecapsule.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/src/adjust-list-param.ts +20 -0
- package/src/async-lock.ts +13 -0
- package/src/clipboard.ts +7 -0
- package/src/closest-element.ts +8 -0
- package/src/context-path.ts +20 -0
- package/src/cookie.ts +18 -0
- package/src/detect-overflow.ts +6 -0
- package/src/format.ts +12 -0
- package/src/logger.ts +15 -4
- package/src/mixins/infinite-scrollable.ts +24 -0
- package/src/os.ts +4 -0
- package/src/password-pattern.ts +15 -0
- package/src/stringify-bignum.ts +12 -0
- package/src/timecapsule/snapshot-taker.ts +41 -4
- package/src/timecapsule/timecapsule.ts +50 -4
@@ -1,10 +1,11 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright © HatioLab Inc. All rights reserved.
|
3
|
-
*/
|
4
|
-
|
5
1
|
import { TimeCapsule } from './timecapsule'
|
6
2
|
import debounce from 'lodash-es/debounce'
|
7
3
|
|
4
|
+
/**
|
5
|
+
* A function that takes a SnapshotTaker as an argument and initiates snapshot creation
|
6
|
+
* using a debouncer to delay the process.
|
7
|
+
* @param {SnapshotTaker} taker - The SnapshotTaker instance to trigger snapshots for.
|
8
|
+
*/
|
8
9
|
var debouncer = debounce(
|
9
10
|
taker => {
|
10
11
|
if (!taker.brake) {
|
@@ -15,15 +16,28 @@ var debouncer = debounce(
|
|
15
16
|
{ leading: true, trailing: false }
|
16
17
|
)
|
17
18
|
|
19
|
+
/**
|
20
|
+
* Function to trigger snapshot creation for a SnapshotTaker instance.
|
21
|
+
* Checks if the taker is in a brake state or not dirty before triggering the snapshot.
|
22
|
+
* @param {SnapshotTaker} taker - The SnapshotTaker instance to create a snapshot for.
|
23
|
+
*/
|
18
24
|
function take_snapshot(taker: SnapshotTaker) {
|
19
25
|
if (taker.brake || !taker.dirty) return
|
20
26
|
debouncer(taker)
|
21
27
|
}
|
22
28
|
|
29
|
+
/**
|
30
|
+
* Type definition for holding state information.
|
31
|
+
* @typedef {Object} StateHolder
|
32
|
+
* @property {*} state - The state to be held.
|
33
|
+
*/
|
23
34
|
export type StateHolder = {
|
24
35
|
state: any
|
25
36
|
}
|
26
37
|
|
38
|
+
/**
|
39
|
+
* Class responsible for taking and managing snapshots of state.
|
40
|
+
*/
|
27
41
|
export class SnapshotTaker {
|
28
42
|
private _brake: boolean = false
|
29
43
|
|
@@ -32,23 +46,38 @@ export class SnapshotTaker {
|
|
32
46
|
state_holder?: StateHolder
|
33
47
|
timecapsule?: TimeCapsule
|
34
48
|
|
49
|
+
/**
|
50
|
+
* Creates an instance of SnapshotTaker.
|
51
|
+
* @param {*} state_holder - The object that holds the state to be snapshot.
|
52
|
+
* @param {TimeCapsule} timecapsule - The TimeCapsule instance associated with this SnapshotTaker.
|
53
|
+
*/
|
35
54
|
constructor(state_holder: any, timecapsule: TimeCapsule) {
|
36
55
|
this.state_holder = state_holder
|
37
56
|
this.timecapsule = timecapsule
|
38
57
|
this.timecapsule.snapshot_taker = this
|
39
58
|
}
|
40
59
|
|
60
|
+
/**
|
61
|
+
* Disposes of the SnapshotTaker and clears associated references.
|
62
|
+
*/
|
41
63
|
dispose() {
|
42
64
|
delete this.state_holder
|
43
65
|
delete this.timecapsule
|
44
66
|
}
|
45
67
|
|
68
|
+
/**
|
69
|
+
* Marks the SnapshotTaker as dirty and initiates snapshot creation.
|
70
|
+
*/
|
46
71
|
touch() {
|
47
72
|
this.dirty = true
|
48
73
|
take_snapshot(this)
|
49
74
|
}
|
50
75
|
|
51
76
|
/* 모든 조건에 관계없이 현재 상태를 snapshot으로 취한다. */
|
77
|
+
/**
|
78
|
+
* Takes a snapshot of the current state.
|
79
|
+
* @param {boolean} [force=false] - If true, the snapshot is taken even if not dirty.
|
80
|
+
*/
|
52
81
|
take(force: boolean = false) {
|
53
82
|
if (this.dirty || force) {
|
54
83
|
this.timecapsule?.snapshot(this.state_holder?.state)
|
@@ -56,11 +85,19 @@ export class SnapshotTaker {
|
|
56
85
|
}
|
57
86
|
}
|
58
87
|
|
88
|
+
/**
|
89
|
+
* Gets the brake state of the SnapshotTaker.
|
90
|
+
* @returns {boolean} - true if the brake is active, false otherwise.
|
91
|
+
*/
|
59
92
|
get brake() {
|
60
93
|
return this._brake
|
61
94
|
}
|
62
95
|
|
63
96
|
/* 마우스를 드래깅하는 동안, 보통 brake 를 ON 시킨다. */
|
97
|
+
/**
|
98
|
+
* Sets the brake state of the SnapshotTaker and initiates snapshot creation.
|
99
|
+
* @param {boolean} brake - The new brake state.
|
100
|
+
*/
|
64
101
|
set brake(brake) {
|
65
102
|
this._brake = !!brake
|
66
103
|
take_snapshot(this)
|
@@ -1,11 +1,10 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright © HatioLab Inc. All rights reserved.
|
3
|
-
*/
|
4
|
-
|
5
1
|
import { debug, error, warn } from '../logger'
|
6
2
|
|
7
3
|
import { SnapshotTaker } from './snapshot-taker'
|
8
4
|
|
5
|
+
/**
|
6
|
+
* A utility class for managing and navigating through a history of snapshots.
|
7
|
+
*/
|
9
8
|
export class TimeCapsule {
|
10
9
|
private q: Array<any> = []
|
11
10
|
private maxsize = 10
|
@@ -13,6 +12,11 @@ export class TimeCapsule {
|
|
13
12
|
|
14
13
|
private _snapshot_taker: SnapshotTaker | null = null
|
15
14
|
|
15
|
+
/**
|
16
|
+
* Creates an instance of TimeCapsule.
|
17
|
+
* @param {number} maxsize - The maximum number of snapshots to store.
|
18
|
+
* @param {any} [start_state] - The initial state to be stored as the first snapshot (optional).
|
19
|
+
*/
|
16
20
|
constructor(maxsize: number, start_state?: any) {
|
17
21
|
maxsize = Number(maxsize)
|
18
22
|
|
@@ -28,10 +32,17 @@ export class TimeCapsule {
|
|
28
32
|
}
|
29
33
|
}
|
30
34
|
|
35
|
+
/**
|
36
|
+
* Disposes of the TimeCapsule and clears all stored snapshots.
|
37
|
+
*/
|
31
38
|
dispose() {
|
32
39
|
this.reset()
|
33
40
|
}
|
34
41
|
|
42
|
+
/**
|
43
|
+
* Captures a snapshot of the current state and stores it.
|
44
|
+
* @param {any} state - The state to be captured as a snapshot.
|
45
|
+
*/
|
35
46
|
snapshot(state: any) {
|
36
47
|
this.q.splice(this.pos + 1, this.q.length - (this.pos + 1), state)
|
37
48
|
|
@@ -42,6 +53,10 @@ export class TimeCapsule {
|
|
42
53
|
this.pos = this.q.length - 1
|
43
54
|
}
|
44
55
|
|
56
|
+
/**
|
57
|
+
* Moves forward to the next snapshot in the history.
|
58
|
+
* @returns {any} The next state snapshot if available, or logs a warning if not.
|
59
|
+
*/
|
45
60
|
forward() {
|
46
61
|
if (this.snapshot_taker) this.snapshot_taker.take()
|
47
62
|
|
@@ -51,6 +66,10 @@ export class TimeCapsule {
|
|
51
66
|
warn('Not forwardable.')
|
52
67
|
}
|
53
68
|
|
69
|
+
/**
|
70
|
+
* Moves backward to the previous snapshot in the history.
|
71
|
+
* @returns {any} The previous state snapshot if available, or logs a warning if not.
|
72
|
+
*/
|
54
73
|
backward() {
|
55
74
|
if (this.snapshot_taker) this.snapshot_taker.take()
|
56
75
|
|
@@ -60,32 +79,59 @@ export class TimeCapsule {
|
|
60
79
|
warn('Not backwardable.')
|
61
80
|
}
|
62
81
|
|
82
|
+
/**
|
83
|
+
* Gets the current state snapshot.
|
84
|
+
* @returns {any} The current state snapshot if available, or logs a warning if not.
|
85
|
+
*/
|
63
86
|
get current() {
|
64
87
|
if (this.pos !== -1) return this.q[this.pos]
|
65
88
|
|
66
89
|
warn('Non state has been recorded.')
|
67
90
|
}
|
68
91
|
|
92
|
+
/**
|
93
|
+
* Gets the number of snapshots stored in the TimeCapsule.
|
94
|
+
* @returns {number} The count of stored snapshots.
|
95
|
+
*/
|
69
96
|
get length() {
|
70
97
|
return this.q.length
|
71
98
|
}
|
72
99
|
|
100
|
+
/**
|
101
|
+
* Checks if there is a snapshot available to move forward.
|
102
|
+
* @returns {boolean} True if moving forward is possible, otherwise false.
|
103
|
+
*/
|
73
104
|
get forwardable() {
|
74
105
|
return this.pos < this.q.length - 1
|
75
106
|
}
|
76
107
|
|
108
|
+
/**
|
109
|
+
* Checks if there is a snapshot available to move backward.
|
110
|
+
* @returns {boolean} True if moving backward is possible, otherwise false.
|
111
|
+
*/
|
77
112
|
get backwardable() {
|
78
113
|
return this.pos > 0
|
79
114
|
}
|
80
115
|
|
116
|
+
/**
|
117
|
+
* Gets the SnapshotTaker associated with this TimeCapsule.
|
118
|
+
* @returns {SnapshotTaker | null} The associated SnapshotTaker, or null if not set.
|
119
|
+
*/
|
81
120
|
get snapshot_taker(): SnapshotTaker | null {
|
82
121
|
return this._snapshot_taker
|
83
122
|
}
|
84
123
|
|
124
|
+
/**
|
125
|
+
* Sets the SnapshotTaker for this TimeCapsule.
|
126
|
+
* @param {SnapshotTaker | null} snapshot_taker - The SnapshotTaker instance to associate with this TimeCapsule.
|
127
|
+
*/
|
85
128
|
set snapshot_taker(snapshot_taker: SnapshotTaker | null) {
|
86
129
|
this._snapshot_taker = snapshot_taker
|
87
130
|
}
|
88
131
|
|
132
|
+
/**
|
133
|
+
* Resets the TimeCapsule, clearing all stored snapshots and resetting the position.
|
134
|
+
*/
|
89
135
|
reset() {
|
90
136
|
this.q = []
|
91
137
|
this.pos = -1
|