@quenty/counter 7.17.0 → 7.17.1
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 +11 -0
- package/package.json +7 -7
- package/src/Shared/Counter.lua +27 -11
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [7.17.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/counter@7.17.0...@quenty/counter@7.17.1) (2025-04-05)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Add types to packages ([2374fb2](https://github.com/Quenty/NevermoreEngine/commit/2374fb2b043cfbe0e9b507b3316eec46a4e353a0))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [7.17.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/counter@7.16.2...@quenty/counter@7.17.0) (2025-04-02)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @quenty/counter
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/counter",
|
|
3
|
-
"version": "7.17.
|
|
3
|
+
"version": "7.17.1",
|
|
4
4
|
"description": "Helps count a total value",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"Quenty"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@quenty/baseobject": "^10.8.
|
|
29
|
-
"@quenty/loader": "^10.8.
|
|
30
|
-
"@quenty/maid": "^3.4.
|
|
31
|
-
"@quenty/rx": "^13.17.
|
|
32
|
-
"@quenty/valueobject": "^13.17.
|
|
28
|
+
"@quenty/baseobject": "^10.8.1",
|
|
29
|
+
"@quenty/loader": "^10.8.1",
|
|
30
|
+
"@quenty/maid": "^3.4.1",
|
|
31
|
+
"@quenty/rx": "^13.17.1",
|
|
32
|
+
"@quenty/valueobject": "^13.17.1"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "78c3ac0ab08dd18085b6e6e6e4f745e76ed99f68"
|
|
38
38
|
}
|
package/src/Shared/Counter.lua
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
@class Counter
|
|
3
4
|
]=]
|
|
@@ -8,18 +9,35 @@ local BaseObject = require("BaseObject")
|
|
|
8
9
|
local Maid = require("Maid")
|
|
9
10
|
local Observable = require("Observable")
|
|
10
11
|
local ValueObject = require("ValueObject")
|
|
12
|
+
local _Signal = require("Signal")
|
|
11
13
|
|
|
12
14
|
local Counter = setmetatable({}, BaseObject)
|
|
13
15
|
Counter.ClassName = "Counter"
|
|
14
16
|
Counter.__index = Counter
|
|
15
17
|
|
|
18
|
+
export type Counter = typeof(setmetatable(
|
|
19
|
+
{} :: {
|
|
20
|
+
_maid: Maid.Maid,
|
|
21
|
+
_count: ValueObject.ValueObject<number>,
|
|
22
|
+
|
|
23
|
+
--[=[
|
|
24
|
+
Fires when the count changes
|
|
25
|
+
@readonly
|
|
26
|
+
@prop Changed Signal.Signal<number>
|
|
27
|
+
@within Counter
|
|
28
|
+
]=]
|
|
29
|
+
Changed: _Signal.Signal<number>,
|
|
30
|
+
},
|
|
31
|
+
Counter
|
|
32
|
+
))
|
|
33
|
+
|
|
16
34
|
--[=[
|
|
17
35
|
Creates a new counter
|
|
18
36
|
|
|
19
37
|
@return Counter
|
|
20
38
|
]=]
|
|
21
|
-
function Counter.new()
|
|
22
|
-
local self = setmetatable(BaseObject.new(), Counter)
|
|
39
|
+
function Counter.new(): Counter
|
|
40
|
+
local self = setmetatable(BaseObject.new() :: any, Counter)
|
|
23
41
|
|
|
24
42
|
self._count = self._maid:Add(ValueObject.new(0, "number"))
|
|
25
43
|
|
|
@@ -28,13 +46,12 @@ function Counter.new()
|
|
|
28
46
|
return self
|
|
29
47
|
end
|
|
30
48
|
|
|
31
|
-
|
|
32
49
|
--[=[
|
|
33
50
|
Returns the current count
|
|
34
51
|
|
|
35
52
|
@return number
|
|
36
53
|
]=]
|
|
37
|
-
function Counter
|
|
54
|
+
function Counter.GetValue(self: Counter): number
|
|
38
55
|
return self._count.Value
|
|
39
56
|
end
|
|
40
57
|
|
|
@@ -43,18 +60,17 @@ end
|
|
|
43
60
|
|
|
44
61
|
@return number
|
|
45
62
|
]=]
|
|
46
|
-
function Counter
|
|
63
|
+
function Counter.Observe(self: Counter)
|
|
47
64
|
return self._count:Observe()
|
|
48
65
|
end
|
|
49
66
|
|
|
50
|
-
|
|
51
67
|
--[=[
|
|
52
68
|
Adds an amount to the counter.
|
|
53
69
|
|
|
54
70
|
@param amount number | Observable<number>
|
|
55
71
|
@return MaidTask
|
|
56
72
|
]=]
|
|
57
|
-
function Counter
|
|
73
|
+
function Counter.Add(self: Counter, amount: number): () -> ()
|
|
58
74
|
if type(amount) == "number" then
|
|
59
75
|
self._count.Value = self._count.Value + amount
|
|
60
76
|
|
|
@@ -76,7 +92,7 @@ function Counter:Add(amount)
|
|
|
76
92
|
end
|
|
77
93
|
end
|
|
78
94
|
|
|
79
|
-
function Counter
|
|
95
|
+
function Counter._addObservable(self: Counter, observeAmount: Observable.Observable<number>): () -> ()
|
|
80
96
|
assert(Observable.isObservable(observeAmount), "Bad observeAmount")
|
|
81
97
|
|
|
82
98
|
local lastCount = 0
|
|
@@ -100,13 +116,13 @@ function Counter:_addObservable(observeAmount)
|
|
|
100
116
|
self._count.Value = self._count.Value - delta
|
|
101
117
|
end)
|
|
102
118
|
|
|
103
|
-
self._maid[maid] = maid
|
|
119
|
+
self._maid[maid :: any] = maid
|
|
104
120
|
maid:GiveTask(function()
|
|
105
|
-
self._maid[maid] = nil
|
|
121
|
+
self._maid[maid :: any] = nil
|
|
106
122
|
end)
|
|
107
123
|
|
|
108
124
|
return function()
|
|
109
|
-
self._maid[maid] = nil
|
|
125
|
+
self._maid[maid :: any] = nil
|
|
110
126
|
end
|
|
111
127
|
end
|
|
112
128
|
|