@quenty/instanceutils 4.2.1-canary.261.5628274.0 → 5.1.0

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,7 +3,18 @@
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
- ## [4.2.1-canary.261.5628274.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/instanceutils@4.2.0...@quenty/instanceutils@4.2.1-canary.261.5628274.0) (2022-05-21)
6
+ # [5.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/instanceutils@5.0.0...@quenty/instanceutils@5.1.0) (2022-06-21)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add RxInstanceUtils.observeChildrenOfNameBrio ([5e5e9a5](https://github.com/Quenty/NevermoreEngine/commit/5e5e9a52bf6cd164bb59f9dc1fdba4470fa6e2dc))
12
+
13
+
14
+
15
+
16
+
17
+ # [5.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/instanceutils@4.2.0...@quenty/instanceutils@5.0.0) (2022-05-21)
7
18
 
8
19
 
9
20
  ### Features
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014-2021 Quenty
3
+ Copyright (c) 2014-2022 Quenty
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/instanceutils",
3
- "version": "4.2.1-canary.261.5628274.0",
3
+ "version": "5.1.0",
4
4
  "description": "Utility functions involving instances in Roblox",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -26,13 +26,14 @@
26
26
  "Quenty"
27
27
  ],
28
28
  "dependencies": {
29
- "@quenty/brio": "5.2.1-canary.261.5628274.0",
30
- "@quenty/loader": "4.1.1-canary.261.5628274.0",
31
- "@quenty/maid": "2.3.0",
32
- "@quenty/rx": "4.2.1-canary.261.5628274.0"
29
+ "@quenty/brio": "^6.1.0",
30
+ "@quenty/loader": "^5.0.0",
31
+ "@quenty/maid": "^2.3.0",
32
+ "@quenty/rx": "^5.1.0",
33
+ "@quenty/symbol": "^2.1.0"
33
34
  },
34
35
  "publishConfig": {
35
36
  "access": "public"
36
37
  },
37
- "gitHead": "5628274461f4fa0135e63b62e99fcd508d4c94f9"
38
+ "gitHead": "c8732cc5dea767b3ff362db43137e2a16da7bc0d"
38
39
  }
@@ -16,6 +16,9 @@ local Brio = require("Brio")
16
16
  local Maid = require("Maid")
17
17
  local Observable = require("Observable")
18
18
  local Rx = require("Rx")
19
+ local Symbol = require("Symbol")
20
+
21
+ local UNSET_VALUE = Symbol.named("unsetValue")
19
22
 
20
23
  local RxInstanceUtils = {}
21
24
 
@@ -109,15 +112,29 @@ function RxInstanceUtils.observePropertyBrio(instance, propertyName, predicate)
109
112
 
110
113
  return Observable.new(function(sub)
111
114
  local maid = Maid.new()
115
+ local lastValue = UNSET_VALUE
112
116
 
113
117
  local function handlePropertyChanged()
114
- maid._property = nil
115
-
116
118
  local propertyValue = instance[propertyName]
117
- if not predicate or predicate(propertyValue) then
118
- local brio = Brio.new(instance[propertyName])
119
- maid._property = brio
120
- sub:Fire(brio)
119
+
120
+ -- Deferred events can cause multiple values to be queued at once
121
+ -- but we operate at this post-deferred layer, so lets only output
122
+ -- reflected values.
123
+ if lastValue ~= propertyValue then
124
+ lastValue = propertyValue
125
+
126
+ if not predicate or predicate(propertyValue) then
127
+ local brio = Brio.new(instance[propertyName])
128
+
129
+ maid._lastBrio = brio
130
+
131
+ -- The above line can cause us to be overwritten so make sure before firing.
132
+ if maid._lastBrio == brio then
133
+ sub:Fire(brio)
134
+ end
135
+ else
136
+ maid._lastBrio = nil
137
+ end
121
138
  end
122
139
  end
123
140
 
@@ -182,6 +199,59 @@ function RxInstanceUtils.observeLastNamedChildBrio(parent, className, name)
182
199
  end)
183
200
  end
184
201
 
202
+ --[=[
203
+ Observes the children with a specific name.
204
+
205
+ @param parent Instance
206
+ @param className string
207
+ @param name string
208
+ @return Observable<Brio<Instance>>
209
+ ]=]
210
+ function RxInstanceUtils.observeChildrenOfNameBrio(parent, className, name)
211
+ assert(typeof(parent) == "Instance", "Bad parent")
212
+ assert(type(className) == "string", "Bad className")
213
+ assert(type(name) == "string", "Bad name")
214
+
215
+ return Observable.new(function(sub)
216
+ local topMaid = Maid.new()
217
+
218
+ local function handleChild(child)
219
+ if not child:IsA(className) then
220
+ return
221
+ end
222
+
223
+ local maid = Maid.new()
224
+
225
+ local function handleNameChanged()
226
+ if child.Name == name then
227
+ local brio = Brio.new(child)
228
+ maid._brio = brio
229
+
230
+ sub:Fire(brio)
231
+ else
232
+ maid._brio = nil
233
+ end
234
+ end
235
+
236
+ maid:GiveTask(child:GetPropertyChangedSignal("Name"):Connect(handleNameChanged))
237
+ handleNameChanged()
238
+
239
+ topMaid[child] = maid
240
+ end
241
+
242
+ topMaid:GiveTask(parent.ChildAdded:Connect(handleChild))
243
+ topMaid:GiveTask(parent.ChildRemoved:Connect(function(child)
244
+ topMaid[child] = nil
245
+ end))
246
+
247
+ for _, child in pairs(parent:GetChildren()) do
248
+ handleChild(child)
249
+ end
250
+
251
+ return topMaid
252
+ end)
253
+ end
254
+
185
255
  --[=[
186
256
  Observes all children of a specific class
187
257