@quenty/brio 14.7.0 → 14.8.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,6 +3,23 @@
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
+ # [14.8.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/brio@14.7.0...@quenty/brio@14.8.0) (2024-10-04)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Brio values are fixed ([7170cb0](https://github.com/Quenty/NevermoreEngine/commit/7170cb0c5ec9cd9af7e298f6eb521cda04eebf34))
12
+
13
+
14
+ ### Performance Improvements
15
+
16
+ * Avoid creating a new maid when needed ([cbbb482](https://github.com/Quenty/NevermoreEngine/commit/cbbb48295e602eddf20ee0d4ca3af98a7edac86e))
17
+ * Brio wraps table.pack directly which reduces table count ([4bb32c0](https://github.com/Quenty/NevermoreEngine/commit/4bb32c0b2859762fb6400c2f0153092bc0e914c6))
18
+
19
+
20
+
21
+
22
+
6
23
  # [14.7.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/brio@14.6.0...@quenty/brio@14.7.0) (2024-09-25)
7
24
 
8
25
  **Note:** Version bump only for package @quenty/brio
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/brio",
3
- "version": "14.7.0",
3
+ "version": "14.8.0",
4
4
  "description": "Brios wrap an object and either are alive or dead",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -26,14 +26,14 @@
26
26
  "Quenty"
27
27
  ],
28
28
  "dependencies": {
29
- "@quenty/loader": "^10.5.0",
30
- "@quenty/maid": "^3.3.0",
31
- "@quenty/rx": "^13.7.0",
32
- "@quenty/signal": "^7.6.0",
29
+ "@quenty/loader": "^10.6.0",
30
+ "@quenty/maid": "^3.4.0",
31
+ "@quenty/rx": "^13.8.0",
32
+ "@quenty/signal": "^7.7.0",
33
33
  "@quenty/steputils": "^3.5.0"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "9b17fe79cddd071f0f06a9d35184e76b44bd6fe6"
38
+ "gitHead": "035abfa088c854a73e1c65b350267eaa17669646"
39
39
  }
@@ -90,9 +90,7 @@ end
90
90
  @return Brio
91
91
  ]=]
92
92
  function Brio.new(...) -- Wrap
93
- return setmetatable({
94
- _values = table.pack(...);
95
- }, Brio)
93
+ return setmetatable(table.pack(...), Brio)
96
94
  end
97
95
 
98
96
  --[=[
@@ -159,7 +157,7 @@ end
159
157
  @return boolean
160
158
  ]=]
161
159
  function Brio:IsDead()
162
- return self._values == nil
160
+ return self.n == nil
163
161
  end
164
162
 
165
163
  --[=[
@@ -170,7 +168,7 @@ end
170
168
  ```
171
169
  ]=]
172
170
  function Brio:ErrorIfDead()
173
- if not self._values then
171
+ if not self.n then
174
172
  error("[Brio.ErrorIfDead] - Brio is dead")
175
173
  end
176
174
  end
@@ -195,7 +193,7 @@ end
195
193
  @return Maid
196
194
  ]=]
197
195
  function Brio:ToMaid()
198
- assert(self._values ~= nil, "Brio is dead")
196
+ assert(self.n ~= nil, "Brio is dead")
199
197
 
200
198
  local maid = Maid.new()
201
199
 
@@ -229,9 +227,9 @@ end
229
227
  @return any
230
228
  ]=]
231
229
  function Brio:GetValue()
232
- assert(self._values, "Brio is dead")
230
+ assert(self.n, "Brio is dead")
233
231
 
234
- return unpack(self._values, 1, self._values.n)
232
+ return unpack(self, 1, self.n)
235
233
  end
236
234
 
237
235
  --[=[
@@ -241,9 +239,9 @@ end
241
239
  @return { n: number, ... T }
242
240
  ]=]
243
241
  function Brio:GetPackedValues()
244
- assert(self._values, "Brio is dead")
242
+ assert(self.n, "Brio is dead")
245
243
 
246
- return self._values
244
+ return self
247
245
  end
248
246
 
249
247
  --[=[
@@ -262,16 +260,19 @@ end
262
260
  ```
263
261
  ]=]
264
262
  function Brio:Destroy()
265
- if not self._values then
263
+ if not self.n then
266
264
  return
267
265
  end
268
266
 
269
- self._values = nil
267
+ local diedEvent = self._diedEvent
270
268
 
271
- if self._diedEvent then
272
- self._diedEvent:Fire()
273
- self._diedEvent:Destroy()
274
- self._diedEvent = nil
269
+ table.clear(self)
270
+ table.freeze(self)
271
+
272
+ if diedEvent then
273
+ diedEvent:Fire()
274
+ diedEvent:Destroy()
275
+ diedEvent = nil
275
276
  end
276
277
  end
277
278
 
@@ -26,9 +26,18 @@ function BrioUtils.clone(brio)
26
26
 
27
27
  local newBrio = Brio.new(brio:GetValue())
28
28
 
29
- newBrio:ToMaid():GiveTask(brio:GetDiedSignal():Connect(function()
29
+ local connection
30
+ local otherConnection
31
+ connection = brio:GetDiedSignal():Connect(function()
32
+ connection:Disconnect()
33
+ otherConnection:Disconnect()
30
34
  newBrio:Kill()
31
- end))
35
+ end)
36
+
37
+ otherConnection = newBrio:GetDiedSignal():Connect(function()
38
+ otherConnection:Disconnect()
39
+ connection:Disconnect()
40
+ end)
32
41
 
33
42
  return newBrio
34
43
  end
@@ -164,7 +173,7 @@ function BrioUtils.extend(brio, ...)
164
173
  return Brio.DEAD
165
174
  end
166
175
 
167
- local values = brio._values
176
+ local values = brio:GetPackedValues()
168
177
  local current = {}
169
178
  for i=1, values.n do
170
179
  current[i] = values[i]
@@ -202,7 +211,7 @@ function BrioUtils.prepend(brio, ...)
202
211
  return Brio.DEAD
203
212
  end
204
213
 
205
- local values = brio._values
214
+ local values = brio:GetPackedValues()
206
215
  local current = {}
207
216
  local otherValues = table.pack(...)
208
217
  for i=1, otherValues.n do
@@ -241,13 +250,13 @@ function BrioUtils.merge(brio, otherBrio)
241
250
  return Brio.DEAD
242
251
  end
243
252
 
244
- local values = brio._values
253
+ local values = brio:GetPackedValues()
245
254
  local current = {}
246
255
  for i=1, values.n do
247
256
  current[i] = values[i]
248
257
  end
249
258
 
250
- local otherValues = otherBrio._values
259
+ local otherValues = otherBrio:GetPackedValues()
251
260
  for i=1, otherValues.n do
252
261
  current[values.n+i] = otherValues[i]
253
262
  end
@@ -782,29 +782,24 @@ function RxBrioUtils.switchToBrio(predicate)
782
782
  local topMaid = Maid.new()
783
783
 
784
784
  topMaid:GiveTask(source:Subscribe(function(result, ...)
785
+ -- Always kill previous brio first
786
+ topMaid._last = nil
787
+
785
788
  if Brio.isBrio(result) then
786
789
  if result:IsDead() then
787
- topMaid._last = nil
788
790
  return
789
791
  end
790
792
 
791
793
  if predicate == nil or predicate(result:GetValue()) then
792
- local maid = result:ToMaid()
793
- local newBrio = maid:Add(Brio.new(result:GetValue()))
794
+ local newBrio = BrioUtils.clone(result)
795
+ topMaid._last = newBrio
794
796
  sub:Fire(newBrio)
795
-
796
- topMaid._last = maid
797
- else
798
- topMaid._last = nil
799
797
  end
800
798
  else
801
799
  if predicate == nil or predicate(result, ...) then
802
800
  local newBrio = Brio.new(result, ...)
803
-
804
801
  topMaid._last = newBrio
805
802
  sub:Fire(newBrio)
806
- else
807
- topMaid._last = nil
808
803
  end
809
804
  end
810
805
  end, sub:GetFailComplete()))