@quenty/throttle 10.9.2 → 10.9.3

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 CHANGED
@@ -3,6 +3,14 @@
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
+ ## [10.9.3](https://github.com/Quenty/NevermoreEngine/compare/@quenty/throttle@10.9.2...@quenty/throttle@10.9.3) (2025-04-10)
7
+
8
+ **Note:** Version bump only for package @quenty/throttle
9
+
10
+
11
+
12
+
13
+
6
14
  ## [10.9.2](https://github.com/Quenty/NevermoreEngine/compare/@quenty/throttle@10.9.0...@quenty/throttle@10.9.2) (2025-04-07)
7
15
 
8
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/throttle",
3
- "version": "10.9.2",
3
+ "version": "10.9.3",
4
4
  "description": "Adds the throttle function to Roblox",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -26,8 +26,8 @@
26
26
  "Quenty"
27
27
  ],
28
28
  "dependencies": {
29
- "@quenty/loader": "^10.8.2",
30
- "@quenty/typeutils": "^1.0.2"
29
+ "@quenty/loader": "^10.8.3",
30
+ "@quenty/typeutils": "^1.0.3"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@quenty/loader": "file:../loader"
@@ -35,5 +35,5 @@
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "64def70499ec067077ee39f279936b620b217847"
38
+ "gitHead": "b06c070ae91d5dab7bd8de6e290ad2caabb15d8f"
39
39
  }
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  Throttles execution of a functon. Does both leading, and following
3
4
  @class ThrottledFunction
@@ -13,8 +14,27 @@ local ThrottledFunction = {}
13
14
  ThrottledFunction.ClassName = "ThrottledFunction"
14
15
  ThrottledFunction.__index = ThrottledFunction
15
16
 
16
- function ThrottledFunction.new(timeoutInSeconds: number, func, config: ThrottleConfig)
17
- local self = setmetatable({}, ThrottledFunction)
17
+ export type Func<T...> = (T...) -> ...any
18
+
19
+ export type ThrottledFunction<T...> = typeof(setmetatable(
20
+ {} :: {
21
+ _nextCallTimeStamp: number,
22
+ _timeout: number,
23
+ _func: Func<T...>,
24
+ _trailingValue: any,
25
+ _callLeading: boolean,
26
+ _callTrailing: boolean,
27
+ _callLeadingFirstTime: boolean?,
28
+ },
29
+ {} :: typeof({ __index = ThrottledFunction })
30
+ ))
31
+
32
+ function ThrottledFunction.new<T...>(
33
+ timeoutInSeconds: number,
34
+ func: Func<T...>,
35
+ config: ThrottleConfig
36
+ ): ThrottledFunction<T...>
37
+ local self: ThrottledFunction<T...> = setmetatable({} :: any, ThrottledFunction)
18
38
 
19
39
  self._nextCallTimeStamp = 0
20
40
  self._timeout = timeoutInSeconds or error("No timeoutInSeconds")
@@ -30,7 +50,7 @@ function ThrottledFunction.new(timeoutInSeconds: number, func, config: ThrottleC
30
50
  return self
31
51
  end
32
52
 
33
- function ThrottledFunction:Call<T...>(...: T...)
53
+ function ThrottledFunction.Call<T...>(self: ThrottledFunction<T...>, ...: T...)
34
54
  if self._trailingValue then
35
55
  -- Update the next value to be dispatched
36
56
  self._trailingValue = table.pack(...)
@@ -67,7 +87,7 @@ end
67
87
 
68
88
  ThrottledFunction.__call = ThrottledFunction.Call
69
89
 
70
- function ThrottledFunction:_dispatch()
90
+ function ThrottledFunction._dispatch<T...>(self: ThrottledFunction<T...>)
71
91
  self._nextCallTimeStamp = tick() + self._timeout
72
92
 
73
93
  local trailingValue = self._trailingValue
@@ -78,7 +98,7 @@ function ThrottledFunction:_dispatch()
78
98
  end
79
99
  end
80
100
 
81
- function ThrottledFunction:_configureOrError(throttleConfig: ThrottleConfig)
101
+ function ThrottledFunction._configureOrError<T...>(self: ThrottledFunction<T...>, throttleConfig: ThrottleConfig)
82
102
  if throttleConfig == nil then
83
103
  return
84
104
  end
@@ -102,10 +122,11 @@ function ThrottledFunction:_configureOrError(throttleConfig: ThrottleConfig)
102
122
  assert(self._callLeading or self._callTrailing, "Cannot configure both leading and trailing disabled")
103
123
  end
104
124
 
105
- function ThrottledFunction:Destroy()
106
- self._trailingValue = nil
107
- self._func = nil
108
- setmetatable(self, nil)
125
+ function ThrottledFunction.Destroy<T...>(self: ThrottledFunction<T...>)
126
+ local private: any = self
127
+ private._trailingValue = nil
128
+ private._func = nil
129
+ setmetatable(private, nil)
109
130
  end
110
131
 
111
132
  return ThrottledFunction
@@ -22,7 +22,7 @@ export type ThrottleConfig = ThrottledFunction.ThrottleConfig
22
22
  @param throttleConfig? { leading = true; trailing = true; }
23
23
  @return function
24
24
  ]=]
25
- local function throttle<T...>(timeoutInSeconds: number, func: (T...) -> ...any, throttleConfig: ThrottledFunction.ThrottleConfig): (T...) -> ()
25
+ local function throttle<T...>(timeoutInSeconds: number, func: ThrottledFunction.Func<T...>, throttleConfig: ThrottledFunction.ThrottleConfig): (T...) -> ()
26
26
  assert(type(timeoutInSeconds) == "number", "timeoutInSeconds is not a number")
27
27
  assert(type(func) == "function", "func is not a function")
28
28