@quenty/brio 14.17.0 → 14.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 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
+ ## [14.17.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/brio@14.17.0...@quenty/brio@14.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
  # [14.17.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/brio@14.16.2...@quenty/brio@14.17.0) (2025-04-02)
7
18
 
8
19
  **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.17.0",
3
+ "version": "14.17.1",
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.8.0",
30
- "@quenty/maid": "^3.4.0",
31
- "@quenty/rx": "^13.17.0",
32
- "@quenty/signal": "^7.10.0",
33
- "@quenty/steputils": "^3.5.3"
29
+ "@quenty/loader": "^10.8.1",
30
+ "@quenty/maid": "^3.4.1",
31
+ "@quenty/rx": "^13.17.1",
32
+ "@quenty/signal": "^7.10.1",
33
+ "@quenty/steputils": "^3.5.4"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "e8ea56930e65322fcffc05a1556d5df988068f0b"
38
+ "gitHead": "78c3ac0ab08dd18085b6e6e6e4f745e76ed99f68"
39
39
  }
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  Brios wrap a value (or tuple of values) and are used to convey the lifetime of that
3
4
  object. The brio is better than a maid, by providing the following constraints:
@@ -59,11 +60,19 @@
59
60
  local require = require(script.Parent.loader).load(script)
60
61
 
61
62
  local Maid = require("Maid")
62
- local GoodSignal = require("GoodSignal")
63
+ local Signal = require("Signal")
63
64
 
64
65
  local Brio = {}
65
- Brio.ClassName = "Brio"
66
66
  Brio.__index = Brio
67
+ Brio.ClassName = "Brio"
68
+
69
+ export type Brio<T...> = typeof(setmetatable(
70
+ {} :: {
71
+ n: number?,
72
+ _diedEvent: Signal.Signal<T...>,
73
+ },
74
+ Brio
75
+ ))
67
76
 
68
77
  --[=[
69
78
  Returns whether a value is a Brio.
@@ -74,7 +83,7 @@ Brio.__index = Brio
74
83
  @param value any
75
84
  @return boolean
76
85
  ]=]
77
- function Brio.isBrio(value)
86
+ function Brio.isBrio(value: any): boolean
78
87
  return type(value) == "table" and value.ClassName == "Brio"
79
88
  end
80
89
 
@@ -89,8 +98,8 @@ end
89
98
  @param ... any -- Brio values
90
99
  @return Brio
91
100
  ]=]
92
- function Brio.new(...) -- Wrap
93
- return setmetatable(table.pack(...), Brio)
101
+ function Brio.new<T...>(...: T...): Brio<T...>
102
+ return setmetatable(table.pack(...) :: any, Brio)
94
103
  end
95
104
 
96
105
  --[=[
@@ -101,8 +110,8 @@ end
101
110
  @param ... any -- Brio values
102
111
  @return Brio
103
112
  ]=]
104
- function Brio.delayed(time, ...)
105
- local brio = Brio.new(...)
113
+ function Brio.delayed<T...>(time: number, ...: T...): Brio<T...>
114
+ local brio: Brio<T...> = Brio.new(...)
106
115
  task.delay(time, function()
107
116
  brio:Kill()
108
117
  end)
@@ -129,7 +138,7 @@ end
129
138
 
130
139
  @return Signal
131
140
  ]=]
132
- function Brio:GetDiedSignal()
141
+ function Brio.GetDiedSignal<T...>(self: Brio<T...>): Signal.Signal<T...>
133
142
  if self:IsDead() then
134
143
  error("Brio is dead")
135
144
  end
@@ -138,8 +147,9 @@ function Brio:GetDiedSignal()
138
147
  return self._diedEvent
139
148
  end
140
149
 
141
- self._diedEvent = GoodSignal.new()
142
- return self._diedEvent
150
+ local diedEvent = Signal.new()
151
+ self._diedEvent = diedEvent
152
+ return diedEvent
143
153
  end
144
154
 
145
155
  --[=[
@@ -156,7 +166,7 @@ end
156
166
 
157
167
  @return boolean
158
168
  ]=]
159
- function Brio:IsDead()
169
+ function Brio.IsDead<T...>(self: Brio<T...>): boolean
160
170
  return self.n == nil
161
171
  end
162
172
 
@@ -167,7 +177,7 @@ end
167
177
  brio.DEAD:ErrorIfDead() --> ERROR: [Brio.ErrorIfDead] - Brio is dead
168
178
  ```
169
179
  ]=]
170
- function Brio:ErrorIfDead()
180
+ function Brio.ErrorIfDead<T...>(self: Brio<T...>)
171
181
  if not self.n then
172
182
  error("[Brio.ErrorIfDead] - Brio is dead")
173
183
  end
@@ -192,7 +202,7 @@ end
192
202
 
193
203
  @return Maid
194
204
  ]=]
195
- function Brio:ToMaid()
205
+ function Brio.ToMaid<T...>(self: Brio<T...>): Maid.Maid
196
206
  assert(self.n ~= nil, "Brio is dead")
197
207
 
198
208
  local maid = Maid.new()
@@ -204,7 +214,7 @@ function Brio:ToMaid()
204
214
  return maid
205
215
  end
206
216
 
207
- function Brio:ToMaidAndValue()
217
+ function Brio.ToMaidAndValue<T...>(self: Brio<T...>): (any, T...)
208
218
  return self:ToMaid(), self:GetValue()
209
219
  end
210
220
 
@@ -226,10 +236,10 @@ end
226
236
 
227
237
  @return any
228
238
  ]=]
229
- function Brio:GetValue()
239
+ function Brio.GetValue<T...>(self: Brio<T...>): T...
230
240
  assert(self.n, "Brio is dead")
231
241
 
232
- return unpack(self, 1, self.n)
242
+ return unpack(self :: any, 1, self.n)
233
243
  end
234
244
 
235
245
  --[=[
@@ -238,7 +248,7 @@ end
238
248
  @since 3.6.0
239
249
  @return { n: number, ... T }
240
250
  ]=]
241
- function Brio:GetPackedValues()
251
+ function Brio.GetPackedValues<T...>(self: Brio<T...>)
242
252
  assert(self.n, "Brio is dead")
243
253
 
244
254
  return self
@@ -259,14 +269,14 @@ end
259
269
  print(brio:GetValue()) --> ERROR: Brio is dead
260
270
  ```
261
271
  ]=]
262
- function Brio:Destroy()
272
+ function Brio.Destroy<T...>(self: Brio<T...>)
263
273
  if not self.n then
264
274
  return
265
275
  end
266
276
 
267
- local diedEvent = self._diedEvent
277
+ local diedEvent: any = self._diedEvent
268
278
 
269
- table.clear(self)
279
+ table.clear(self :: any)
270
280
  table.freeze(self)
271
281
 
272
282
  if diedEvent then
@@ -50,7 +50,7 @@ end
50
50
  ]=]
51
51
  function BrioUtils.aliveOnly(brios)
52
52
  local alive = {}
53
- for _, brio in pairs(brios) do
53
+ for _, brio in brios do
54
54
  if not brio:IsDead() then
55
55
  table.insert(alive, brio)
56
56
  end
@@ -65,7 +65,7 @@ end
65
65
  @return Brio<T>
66
66
  ]=]
67
67
  function BrioUtils.firstAlive(brios)
68
- for _, brio in pairs(brios) do
68
+ for _, brio in brios do
69
69
  if not brio:IsDead() then
70
70
  return brio
71
71
  end
@@ -84,7 +84,7 @@ function BrioUtils.flatten(brioTable)
84
84
  local newValue = {}
85
85
  local brios = {}
86
86
 
87
- for key, brio in pairs(brioTable) do
87
+ for key, brio in brioTable do
88
88
  if Brio.isBrio(brio) then
89
89
  if brio:IsDead() then
90
90
  return Brio.DEAD
@@ -109,7 +109,7 @@ end
109
109
  @return Brio<U>
110
110
  ]=]
111
111
  function BrioUtils.first(brios, ...)
112
- for _, brio in pairs(brios) do
112
+ for _, brio in brios do
113
113
  if Brio.isBrio(brio) then
114
114
  if brio:IsDead() then
115
115
  return Brio.DEAD
@@ -120,7 +120,7 @@ function BrioUtils.first(brios, ...)
120
120
  local maid = Maid.new()
121
121
  local topBrio = Brio.new(...)
122
122
 
123
- for _, brio in pairs(brios) do
123
+ for _, brio in brios do
124
124
  if Brio.isBrio(brio) then
125
125
  maid:GiveTask(brio:GetDiedSignal():Connect(function()
126
126
  topBrio:Kill()
@@ -206,7 +206,7 @@ function RxBrioUtils.reduceToAliveList(selectFromBrio)
206
206
  aliveBrios = BrioUtils.aliveOnly(aliveBrios)
207
207
  local values = {}
208
208
  if selectFromBrio then
209
- for _, brio in pairs(aliveBrios) do
209
+ for _, brio in aliveBrios do
210
210
  -- Hope for no side effects
211
211
  local value = selectFromBrio(brio:GetValue())
212
212
  assert(value ~= nil, "Bad value")
@@ -214,7 +214,7 @@ function RxBrioUtils.reduceToAliveList(selectFromBrio)
214
214
  table.insert(values, value)
215
215
  end
216
216
  else
217
- for _, brio in pairs(aliveBrios) do
217
+ for _, brio in aliveBrios do
218
218
  local value = brio:GetValue()
219
219
  assert(value ~= nil, "Bad value")
220
220
 
@@ -489,7 +489,7 @@ function RxBrioUtils.flatCombineLatest(observables)
489
489
  assert(type(observables) == "table", "Bad observables")
490
490
 
491
491
  local newObservables = {}
492
- for key, observable in pairs(observables) do
492
+ for key, observable in observables do
493
493
  if Observable.isObservable(observable) then
494
494
  newObservables[key] = RxBrioUtils.flattenToValueAndNil(observable)
495
495
  else
@@ -576,11 +576,11 @@ function RxBrioUtils.map(project)
576
576
  table.insert(brios, (...))
577
577
  args = (...):GetPackedValues()
578
578
  else
579
- args = {[1] = ...}
579
+ args = { [1] = ... }
580
580
  end
581
581
  else
582
582
  args = {}
583
- for index, item in pairs({...}) do
583
+ for index, item in { ... } do
584
584
  if Brio.isBrio(item) then
585
585
  table.insert(brios, item)
586
586
  args[index] = item:GetValue() -- we lose data here, but I think this is fine
@@ -593,7 +593,7 @@ function RxBrioUtils.map(project)
593
593
 
594
594
  local results = table.pack(project(table.unpack(args, 1, args.n)))
595
595
  local transformedResults = {}
596
- for i=1, results.n do
596
+ for i = 1, results.n do
597
597
  local item = results[i]
598
598
  if Brio.isBrio(item) then
599
599
  table.insert(brios, item) -- add all subsequent brios into this table...
@@ -614,7 +614,7 @@ function RxBrioUtils._mapResult(brio)
614
614
  return BrioUtils.withOtherValues(brio)
615
615
  elseif n == 1 then
616
616
  if Brio.isBrio(...) then
617
- return BrioUtils.first({brio, (...)}, (...):GetValue())
617
+ return BrioUtils.first({ brio, (...) }, (...):GetValue())
618
618
  else
619
619
  return BrioUtils.withOtherValues(brio, ...)
620
620
  end
@@ -622,7 +622,7 @@ function RxBrioUtils._mapResult(brio)
622
622
  local brios = { brio }
623
623
  local args = {}
624
624
 
625
- for index, item in pairs({...}) do
625
+ for index, item in {...} do
626
626
  if Brio.isBrio(item) then
627
627
  table.insert(brios, item)
628
628
  args[index] = item:GetValue() -- we lose data here, but I think this is fine
@@ -677,25 +677,29 @@ function RxBrioUtils.toEmitOnDeathObservable(brio, emitOnDeathValue)
677
677
  if brio:IsDead() then
678
678
  sub:Fire(emitOnDeathValue)
679
679
  sub:Complete()
680
- else
681
- sub:Fire(brio:GetValue())
682
680
 
683
- -- Firing killed the subscription
684
- if not sub:IsPending() then
685
- return
686
- end
681
+ return nil
682
+ end
687
683
 
688
- -- Firing this event actually killed the brio
689
- if brio:IsDead() then
690
- sub:Fire(emitOnDeathValue)
691
- sub:Complete()
692
- else
693
- return brio:GetDiedSignal():Connect(function()
694
- sub:Fire(emitOnDeathValue)
695
- sub:Complete()
696
- end)
697
- end
684
+ sub:Fire(brio:GetValue())
685
+
686
+ -- Firing killed the subscription
687
+ if not sub:IsPending() then
688
+ return nil
689
+ end
690
+
691
+ -- Firing this event actually killed the brio
692
+ if brio:IsDead() then
693
+ sub:Fire(emitOnDeathValue)
694
+ sub:Complete()
695
+
696
+ return nil
698
697
  end
698
+
699
+ return brio:GetDiedSignal():Connect(function()
700
+ sub:Fire(emitOnDeathValue)
701
+ sub:Complete()
702
+ end)
699
703
  end)
700
704
  end
701
705
  end
@@ -722,7 +726,7 @@ end
722
726
  function RxBrioUtils.emitOnDeath(emitOnDeathValue)
723
727
  return Rx.switchMap(function(brio)
724
728
  return RxBrioUtils.toEmitOnDeathObservable(brio, emitOnDeathValue)
725
- end);
729
+ end)
726
730
  end
727
731
 
728
732
  --[=[