@quenty/instanceutils 13.17.0 → 13.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/RxInstanceUtils.lua +65 -39
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
|
+
## [13.17.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/instanceutils@13.17.0...@quenty/instanceutils@13.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
|
# [13.17.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/instanceutils@13.16.2...@quenty/instanceutils@13.17.0) (2025-04-02)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @quenty/instanceutils
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/instanceutils",
|
|
3
|
-
"version": "13.17.
|
|
3
|
+
"version": "13.17.1",
|
|
4
4
|
"description": "Utility functions involving instances in Roblox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
"Quenty"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@quenty/brio": "^14.17.
|
|
30
|
-
"@quenty/loader": "^10.8.
|
|
31
|
-
"@quenty/maid": "^3.4.
|
|
32
|
-
"@quenty/rx": "^13.17.
|
|
33
|
-
"@quenty/symbol": "^3.4.
|
|
29
|
+
"@quenty/brio": "^14.17.1",
|
|
30
|
+
"@quenty/loader": "^10.8.1",
|
|
31
|
+
"@quenty/maid": "^3.4.1",
|
|
32
|
+
"@quenty/rx": "^13.17.1",
|
|
33
|
+
"@quenty/symbol": "^3.4.1"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "78c3ac0ab08dd18085b6e6e6e4f745e76ed99f68"
|
|
39
39
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Utility functions to observe the state of Roblox. This is a very powerful way to query
|
|
3
4
|
Roblox's state.
|
|
@@ -29,15 +30,15 @@ local RxInstanceUtils = {}
|
|
|
29
30
|
@param propertyName string
|
|
30
31
|
@return Observable<T>
|
|
31
32
|
]=]
|
|
32
|
-
function RxInstanceUtils.observeProperty(instance: Instance, propertyName: string)
|
|
33
|
+
function RxInstanceUtils.observeProperty(instance: Instance, propertyName: string): Observable.Observable<any>
|
|
33
34
|
assert(typeof(instance) == "Instance", "'instance' should be of type Instance")
|
|
34
35
|
assert(type(propertyName) == "string", "'propertyName' should be of type string")
|
|
35
36
|
|
|
36
37
|
return Observable.new(function(sub)
|
|
37
38
|
local connection = instance:GetPropertyChangedSignal(propertyName):Connect(function()
|
|
38
|
-
sub:Fire(instance[propertyName], instance)
|
|
39
|
+
sub:Fire((instance :: any)[propertyName], instance)
|
|
39
40
|
end)
|
|
40
|
-
sub:Fire(instance[propertyName], instance)
|
|
41
|
+
sub:Fire((instance :: any)[propertyName], instance)
|
|
41
42
|
|
|
42
43
|
return connection
|
|
43
44
|
end)
|
|
@@ -49,12 +50,12 @@ end
|
|
|
49
50
|
@param instance Instance
|
|
50
51
|
@return Observable<Instance>
|
|
51
52
|
]=]
|
|
52
|
-
function RxInstanceUtils.observeAncestry(instance: Instance)
|
|
53
|
+
function RxInstanceUtils.observeAncestry(instance: Instance): Observable.Observable<Instance>
|
|
53
54
|
local startWithParent = Rx.start(function()
|
|
54
55
|
return instance, instance.Parent
|
|
55
56
|
end)
|
|
56
57
|
|
|
57
|
-
return startWithParent(Rx.fromSignal(instance.AncestryChanged))
|
|
58
|
+
return startWithParent(Rx.fromSignal(instance.AncestryChanged)) :: any
|
|
58
59
|
end
|
|
59
60
|
|
|
60
61
|
--[=[
|
|
@@ -64,14 +65,17 @@ end
|
|
|
64
65
|
@param className string
|
|
65
66
|
@return Observable<Brio<Instance>>
|
|
66
67
|
]=]
|
|
67
|
-
function RxInstanceUtils.observeFirstAncestorBrio(
|
|
68
|
+
function RxInstanceUtils.observeFirstAncestorBrio(
|
|
69
|
+
instance: Instance,
|
|
70
|
+
className: string
|
|
71
|
+
): Observable.Observable<Brio.Brio<Instance>>
|
|
68
72
|
assert(typeof(instance) == "Instance", "Bad instance")
|
|
69
73
|
assert(type(className) == "string", "Bad className")
|
|
70
74
|
|
|
71
75
|
return Observable.new(function(sub)
|
|
72
76
|
local maid = Maid.new()
|
|
73
77
|
|
|
74
|
-
local lastFound = nil
|
|
78
|
+
local lastFound: Instance? = nil
|
|
75
79
|
local function handleAncestryChanged()
|
|
76
80
|
local found = instance:FindFirstAncestorWhichIsA(className)
|
|
77
81
|
|
|
@@ -92,7 +96,7 @@ function RxInstanceUtils.observeFirstAncestorBrio(instance: Instance, className:
|
|
|
92
96
|
handleAncestryChanged()
|
|
93
97
|
|
|
94
98
|
return maid
|
|
95
|
-
end)
|
|
99
|
+
end) :: any
|
|
96
100
|
end
|
|
97
101
|
|
|
98
102
|
--[=[
|
|
@@ -102,10 +106,10 @@ end
|
|
|
102
106
|
@param instance Instance
|
|
103
107
|
@return Observable<Brio<Instance>>
|
|
104
108
|
]=]
|
|
105
|
-
function RxInstanceUtils.observeParentBrio(instance: Instance)
|
|
109
|
+
function RxInstanceUtils.observeParentBrio(instance: Instance): Observable.Observable<Brio.Brio<Instance>>
|
|
106
110
|
return RxInstanceUtils.observePropertyBrio(instance, "Parent", function(parent)
|
|
107
111
|
return parent ~= nil
|
|
108
|
-
end)
|
|
112
|
+
end) :: any
|
|
109
113
|
end
|
|
110
114
|
|
|
111
115
|
--[=[
|
|
@@ -115,7 +119,7 @@ end
|
|
|
115
119
|
@param className string
|
|
116
120
|
@return Observable<Instance?>
|
|
117
121
|
]=]
|
|
118
|
-
function RxInstanceUtils.observeFirstAncestor(instance: Instance, className: string)
|
|
122
|
+
function RxInstanceUtils.observeFirstAncestor(instance: Instance, className: string): Observable.Observable<Instance?>
|
|
119
123
|
assert(typeof(instance) == "Instance", "Bad instance")
|
|
120
124
|
assert(type(className) == "string", "Bad className")
|
|
121
125
|
|
|
@@ -136,8 +140,6 @@ function RxInstanceUtils.observeFirstAncestor(instance: Instance, className: str
|
|
|
136
140
|
end)
|
|
137
141
|
end
|
|
138
142
|
|
|
139
|
-
export type Predicate = (value: Instance) -> boolean
|
|
140
|
-
|
|
141
143
|
--[=[
|
|
142
144
|
Returns a brio of the property value
|
|
143
145
|
|
|
@@ -146,7 +148,11 @@ export type Predicate = (value: Instance) -> boolean
|
|
|
146
148
|
@param predicate ((value: T) -> boolean)? -- Optional filter
|
|
147
149
|
@return Observable<Brio<T>>
|
|
148
150
|
]=]
|
|
149
|
-
function RxInstanceUtils.observePropertyBrio(
|
|
151
|
+
function RxInstanceUtils.observePropertyBrio(
|
|
152
|
+
instance: Instance,
|
|
153
|
+
propertyName: string,
|
|
154
|
+
predicate: Rx.Predicate<any>?
|
|
155
|
+
): Observable.Observable<Brio.Brio<any>>
|
|
150
156
|
assert(typeof(instance) == "Instance", "Bad instance")
|
|
151
157
|
assert(type(propertyName) == "string", "Bad propertyName")
|
|
152
158
|
assert(type(predicate) == "function" or predicate == nil, "Bad predicate")
|
|
@@ -156,7 +162,7 @@ function RxInstanceUtils.observePropertyBrio(instance: Instance, propertyName: s
|
|
|
156
162
|
local lastValue = UNSET_VALUE
|
|
157
163
|
|
|
158
164
|
local function handlePropertyChanged()
|
|
159
|
-
local propertyValue = instance[propertyName]
|
|
165
|
+
local propertyValue = (instance :: any)[propertyName]
|
|
160
166
|
|
|
161
167
|
-- Deferred events can cause multiple values to be queued at once
|
|
162
168
|
-- but we operate at this post-deferred layer, so lets only output
|
|
@@ -165,7 +171,7 @@ function RxInstanceUtils.observePropertyBrio(instance: Instance, propertyName: s
|
|
|
165
171
|
lastValue = propertyValue
|
|
166
172
|
|
|
167
173
|
if not predicate or predicate(propertyValue) then
|
|
168
|
-
local brio = Brio.new(instance[propertyName])
|
|
174
|
+
local brio = Brio.new((instance :: any)[propertyName])
|
|
169
175
|
|
|
170
176
|
maid._lastBrio = brio
|
|
171
177
|
|
|
@@ -183,7 +189,7 @@ function RxInstanceUtils.observePropertyBrio(instance: Instance, propertyName: s
|
|
|
183
189
|
handlePropertyChanged()
|
|
184
190
|
|
|
185
191
|
return maid
|
|
186
|
-
end)
|
|
192
|
+
end) :: any
|
|
187
193
|
end
|
|
188
194
|
|
|
189
195
|
--[=[
|
|
@@ -194,7 +200,11 @@ end
|
|
|
194
200
|
@param name string
|
|
195
201
|
@return Observable<Brio<Instance>>
|
|
196
202
|
]=]
|
|
197
|
-
function RxInstanceUtils.observeLastNamedChildBrio(
|
|
203
|
+
function RxInstanceUtils.observeLastNamedChildBrio(
|
|
204
|
+
parent: Instance,
|
|
205
|
+
className: string,
|
|
206
|
+
name: string
|
|
207
|
+
): Observable.Observable<Brio.Brio<Instance>>
|
|
198
208
|
assert(typeof(parent) == "Instance", "Bad parent")
|
|
199
209
|
assert(type(className) == "string", "Bad className")
|
|
200
210
|
assert(type(name) == "string", "Bad name")
|
|
@@ -202,7 +212,7 @@ function RxInstanceUtils.observeLastNamedChildBrio(parent: Instance, className:
|
|
|
202
212
|
return Observable.new(function(sub)
|
|
203
213
|
local topMaid = Maid.new()
|
|
204
214
|
|
|
205
|
-
local function handleChild(child)
|
|
215
|
+
local function handleChild(child: Instance)
|
|
206
216
|
if not child:IsA(className) then
|
|
207
217
|
return
|
|
208
218
|
end
|
|
@@ -232,12 +242,12 @@ function RxInstanceUtils.observeLastNamedChildBrio(parent: Instance, className:
|
|
|
232
242
|
topMaid[child] = nil
|
|
233
243
|
end))
|
|
234
244
|
|
|
235
|
-
for _, child in
|
|
245
|
+
for _, child in parent:GetChildren() do
|
|
236
246
|
handleChild(child)
|
|
237
247
|
end
|
|
238
248
|
|
|
239
249
|
return topMaid
|
|
240
|
-
end)
|
|
250
|
+
end) :: any
|
|
241
251
|
end
|
|
242
252
|
|
|
243
253
|
--[=[
|
|
@@ -248,7 +258,11 @@ end
|
|
|
248
258
|
@param name string
|
|
249
259
|
@return Observable<Brio<Instance>>
|
|
250
260
|
]=]
|
|
251
|
-
function RxInstanceUtils.observeChildrenOfNameBrio(
|
|
261
|
+
function RxInstanceUtils.observeChildrenOfNameBrio(
|
|
262
|
+
parent: Instance,
|
|
263
|
+
className: string,
|
|
264
|
+
name: string
|
|
265
|
+
): Observable.Observable<Brio.Brio<Instance>>
|
|
252
266
|
assert(typeof(parent) == "Instance", "Bad parent")
|
|
253
267
|
assert(type(className) == "string", "Bad className")
|
|
254
268
|
assert(type(name) == "string", "Bad name")
|
|
@@ -256,7 +270,7 @@ function RxInstanceUtils.observeChildrenOfNameBrio(parent: Instance, className:
|
|
|
256
270
|
return Observable.new(function(sub)
|
|
257
271
|
local topMaid = Maid.new()
|
|
258
272
|
|
|
259
|
-
local function handleChild(child)
|
|
273
|
+
local function handleChild(child: Instance)
|
|
260
274
|
if not child:IsA(className) then
|
|
261
275
|
return
|
|
262
276
|
end
|
|
@@ -285,12 +299,12 @@ function RxInstanceUtils.observeChildrenOfNameBrio(parent: Instance, className:
|
|
|
285
299
|
topMaid[child] = nil
|
|
286
300
|
end))
|
|
287
301
|
|
|
288
|
-
for _, child in
|
|
302
|
+
for _, child in parent:GetChildren() do
|
|
289
303
|
handleChild(child)
|
|
290
304
|
end
|
|
291
305
|
|
|
292
306
|
return topMaid
|
|
293
|
-
end)
|
|
307
|
+
end) :: any
|
|
294
308
|
end
|
|
295
309
|
|
|
296
310
|
--[=[
|
|
@@ -298,9 +312,12 @@ end
|
|
|
298
312
|
|
|
299
313
|
@param parent Instance
|
|
300
314
|
@param className string
|
|
301
|
-
@return Observable<Instance
|
|
315
|
+
@return Observable<Brio<Instance>>
|
|
302
316
|
]=]
|
|
303
|
-
function RxInstanceUtils.observeChildrenOfClassBrio(
|
|
317
|
+
function RxInstanceUtils.observeChildrenOfClassBrio(
|
|
318
|
+
parent: Instance,
|
|
319
|
+
className: string
|
|
320
|
+
): Observable.Observable<Brio.Brio<Instance>>
|
|
304
321
|
assert(typeof(parent) == "Instance", "Bad parent")
|
|
305
322
|
assert(type(className) == "string", "Bad className")
|
|
306
323
|
|
|
@@ -316,14 +333,17 @@ end
|
|
|
316
333
|
@param predicate ((value: Instance) -> boolean)? -- Optional filter
|
|
317
334
|
@return Observable<Brio<Instance>>
|
|
318
335
|
]=]
|
|
319
|
-
function RxInstanceUtils.observeChildrenBrio(
|
|
336
|
+
function RxInstanceUtils.observeChildrenBrio(
|
|
337
|
+
parent: Instance,
|
|
338
|
+
predicate: Rx.Predicate<Instance>?
|
|
339
|
+
): Observable.Observable<Brio.Brio<Instance>>
|
|
320
340
|
assert(typeof(parent) == "Instance", "Bad parent")
|
|
321
341
|
assert(type(predicate) == "function" or predicate == nil, "Bad predicate")
|
|
322
342
|
|
|
323
343
|
return Observable.new(function(sub)
|
|
324
344
|
local maid = Maid.new()
|
|
325
345
|
|
|
326
|
-
local function handleChild(child)
|
|
346
|
+
local function handleChild(child: Instance)
|
|
327
347
|
if not predicate or predicate(child) then
|
|
328
348
|
local value = Brio.new(child)
|
|
329
349
|
maid[child] = value
|
|
@@ -336,12 +356,12 @@ function RxInstanceUtils.observeChildrenBrio(parent: Instance, predicate: Predic
|
|
|
336
356
|
maid[child] = nil
|
|
337
357
|
end))
|
|
338
358
|
|
|
339
|
-
for _, child in
|
|
359
|
+
for _, child in parent:GetChildren() do
|
|
340
360
|
handleChild(child)
|
|
341
361
|
end
|
|
342
362
|
|
|
343
363
|
return maid
|
|
344
|
-
end)
|
|
364
|
+
end) :: any
|
|
345
365
|
end
|
|
346
366
|
|
|
347
367
|
--[=[
|
|
@@ -351,7 +371,10 @@ end
|
|
|
351
371
|
@param predicate ((value: Instance) -> boolean)? -- Optional filter
|
|
352
372
|
@return Observable<Instance, boolean>
|
|
353
373
|
]=]
|
|
354
|
-
function RxInstanceUtils.observeDescendants(
|
|
374
|
+
function RxInstanceUtils.observeDescendants(
|
|
375
|
+
parent: Instance,
|
|
376
|
+
predicate: Rx.Predicate<Instance>?
|
|
377
|
+
): Observable.Observable<Instance, boolean>
|
|
355
378
|
assert(typeof(parent) == "Instance", "Bad parent")
|
|
356
379
|
assert(type(predicate) == "function" or predicate == nil, "Bad predicate")
|
|
357
380
|
|
|
@@ -374,12 +397,12 @@ function RxInstanceUtils.observeDescendants(parent: Instance, predicate: Predica
|
|
|
374
397
|
end
|
|
375
398
|
end))
|
|
376
399
|
|
|
377
|
-
for _, descendant in
|
|
400
|
+
for _, descendant in parent:GetDescendants() do
|
|
378
401
|
handleDescendant(descendant)
|
|
379
402
|
end
|
|
380
403
|
|
|
381
404
|
return maid
|
|
382
|
-
end)
|
|
405
|
+
end) :: any
|
|
383
406
|
end
|
|
384
407
|
|
|
385
408
|
--[=[
|
|
@@ -389,7 +412,10 @@ end
|
|
|
389
412
|
@param predicate ((value: Instance) -> boolean)? -- Optional filter
|
|
390
413
|
@return Observable<Brio<Instance>>
|
|
391
414
|
]=]
|
|
392
|
-
function RxInstanceUtils.observeDescendantsBrio(
|
|
415
|
+
function RxInstanceUtils.observeDescendantsBrio(
|
|
416
|
+
parent: Instance,
|
|
417
|
+
predicate: Rx.Predicate<Instance>?
|
|
418
|
+
): Observable.Observable<Brio.Brio<Instance>>
|
|
393
419
|
assert(typeof(parent) == "Instance", "Bad parent")
|
|
394
420
|
assert(type(predicate) == "function" or predicate == nil, "Bad predicate")
|
|
395
421
|
|
|
@@ -409,12 +435,12 @@ function RxInstanceUtils.observeDescendantsBrio(parent: Instance, predicate: Pre
|
|
|
409
435
|
maid[descendant] = nil
|
|
410
436
|
end))
|
|
411
437
|
|
|
412
|
-
for _, descendant in
|
|
438
|
+
for _, descendant in parent:GetDescendants() do
|
|
413
439
|
handleDescendant(descendant)
|
|
414
440
|
end
|
|
415
441
|
|
|
416
442
|
return maid
|
|
417
|
-
end)
|
|
443
|
+
end) :: any
|
|
418
444
|
end
|
|
419
445
|
|
|
420
446
|
--[=[
|
|
@@ -424,11 +450,11 @@ end
|
|
|
424
450
|
@param className string
|
|
425
451
|
@return Observable<Instance>
|
|
426
452
|
]=]
|
|
427
|
-
function RxInstanceUtils.observeDescendantsOfClassBrio(parent: Instance, className: string)
|
|
453
|
+
function RxInstanceUtils.observeDescendantsOfClassBrio(parent: Instance, className: string): Observable.Observable<Brio.Brio<Instance>>
|
|
428
454
|
assert(typeof(parent) == "Instance", "Bad parent")
|
|
429
455
|
assert(type(className) == "string", "Bad className")
|
|
430
456
|
|
|
431
|
-
return RxInstanceUtils.observeDescendantsBrio(parent, function(child)
|
|
457
|
+
return RxInstanceUtils.observeDescendantsBrio(parent, function(child: Instance)
|
|
432
458
|
return child:IsA(className)
|
|
433
459
|
end)
|
|
434
460
|
end
|