@quenty/statestack 14.18.0 → 14.18.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.18.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/statestack@14.18.0...@quenty/statestack@14.18.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.18.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/statestack@14.17.2...@quenty/statestack@14.18.0) (2025-04-02)
7
18
 
8
19
  **Note:** Version bump only for package @quenty/statestack
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/statestack",
3
- "version": "14.18.0",
3
+ "version": "14.18.1",
4
4
  "description": "Stack of values that allows multiple systems to enable or disable a state",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -25,15 +25,15 @@
25
25
  "Quenty"
26
26
  ],
27
27
  "dependencies": {
28
- "@quenty/baseobject": "^10.8.0",
29
- "@quenty/brio": "^14.17.0",
30
- "@quenty/loader": "^10.8.0",
31
- "@quenty/maid": "^3.4.0",
32
- "@quenty/rx": "^13.17.0",
33
- "@quenty/valueobject": "^13.17.0"
28
+ "@quenty/baseobject": "^10.8.1",
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/valueobject": "^13.17.1"
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
  @class RxStateStackUtils
3
4
  ]=]
@@ -14,10 +15,10 @@ local RxStateStackUtils = {}
14
15
  --[=[
15
16
  Converts the observable of Brios into a statestack.
16
17
 
17
- @param defaultValue T | nil
18
+ @param defaultValue T?
18
19
  @return (source: Observable<Brio<T>>) -> Observable<T?>
19
20
  ]=]
20
- function RxStateStackUtils.topOfStack(defaultValue)
21
+ function RxStateStackUtils.topOfStack<T>(defaultValue: T?): Observable.Transformer<(Brio.Brio<T>), (T)>
21
22
  return function(source)
22
23
  return Observable.new(function(sub)
23
24
  local maid = Maid.new()
@@ -42,8 +43,7 @@ function RxStateStackUtils.topOfStack(defaultValue)
42
43
  update()
43
44
 
44
45
  return maid
45
- end)
46
-
46
+ end) :: any
47
47
  end
48
48
  end
49
49
 
@@ -54,8 +54,8 @@ end
54
54
  @param observable Observable<Brio<T>>
55
55
  @return StateStack<T>
56
56
  ]=]
57
- function RxStateStackUtils.createStateStack(observable)
58
- local stateStack = StateStack.new(nil)
57
+ function RxStateStackUtils.createStateStack<T>(observable: Observable.Observable<Brio.Brio<T>>): StateStack.StateStack<T>
58
+ local stateStack: StateStack.StateStack<T> = StateStack.new(nil) :: any
59
59
 
60
60
  stateStack._maid:GiveTask(observable:Subscribe(function(value)
61
61
  assert(Brio.isBrio(value), "Observable must emit brio")
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  Stack of values that allows multiple systems to enable or disable a state.
3
4
 
@@ -25,74 +26,89 @@ local require = require(script.Parent.loader).load(script)
25
26
 
26
27
  local BaseObject = require("BaseObject")
27
28
  local ValueObject = require("ValueObject")
29
+ local _Brio = require("Brio")
30
+ local _Signal = require("Signal")
31
+ local _Observable = require("Observable")
32
+ local _Maid = require("Maid")
28
33
 
29
34
  local StateStack = setmetatable({}, BaseObject)
30
35
  StateStack.ClassName = "StateStack"
31
36
  StateStack.__index = StateStack
32
37
 
38
+ export type StateStack<T> = typeof(setmetatable(
39
+ {} :: {
40
+ _maid: _Maid.Maid,
41
+ _state: ValueObject.ValueObject<T>,
42
+ _defaultValue: T,
43
+ _stateStack: { { T } },
44
+ Changed: _Signal.Signal<T>,
45
+ },
46
+ { __index = StateStack }
47
+ ))
48
+
33
49
  --[=[
34
50
  Constructs a new StateStack.
35
51
  @param defaultValue any -- The default value to use for the statestack.
36
- @param checkType string | nil
52
+ @param checkType string?
37
53
  @return StateStack
38
54
  ]=]
39
- function StateStack.new(defaultValue, checkType)
40
- local self = setmetatable(BaseObject.new(), StateStack)
55
+ function StateStack.new<T>(defaultValue: T, checkType): StateStack<T>
56
+ local self = setmetatable(BaseObject.new() :: any, StateStack)
41
57
 
42
58
  self._state = self._maid:Add(ValueObject.new(defaultValue, checkType))
43
59
  self._defaultValue = defaultValue
44
60
  self._stateStack = {}
45
61
 
46
- --[=[
62
+ --[=[
47
63
  Fires with the new state
48
64
  @prop Changed Signal<T>
49
65
  @within StateStack
50
66
  ]=]
51
67
  self.Changed = self._state.Changed
52
68
 
53
- return self
69
+ return self :: StateStack<T>
54
70
  end
55
71
 
56
72
  --[=[
57
73
  Gets the count of the stack
58
74
  @return number
59
75
  ]=]
60
- function StateStack:GetCount()
76
+ function StateStack.GetCount<T>(self: StateStack<T>): number
61
77
  return #self._stateStack
62
78
  end
63
79
 
64
80
  --[=[
65
81
  Gets the current state
66
- @return T?
82
+ @return T
67
83
  ]=]
68
- function StateStack:GetState()
84
+ function StateStack.GetState<T>(self: StateStack<T>): T
69
85
  return self._state.Value
70
86
  end
71
87
 
72
88
  --[=[
73
89
  Observes the current value of stack
74
- @return Observable<T?>
90
+ @return Observable<T>
75
91
  ]=]
76
- function StateStack:Observe()
92
+ function StateStack.Observe<T>(self: StateStack<T>): _Observable.Observable<T>
77
93
  return self._state:Observe()
78
94
  end
79
95
 
80
96
  --[=[
81
97
  Observes the current value of stack
82
98
  @param predicate function
83
- @return Observable<T?>
99
+ @return Observable<T>
84
100
  ]=]
85
- function StateStack:ObserveBrio(predicate)
101
+ function StateStack.ObserveBrio<T>(self: StateStack<T>, predicate): _Observable.Observable<_Brio.Brio<T>>
86
102
  return self._state:ObserveBrio(predicate)
87
103
  end
88
104
 
89
105
  --[=[
90
106
  Pushes the current state onto the stack
91
- @param state T?
107
+ @param state T
92
108
  @return function -- Cleanup function to invoke
93
109
  ]=]
94
- function StateStack:PushState(state)
95
- local data = { state }
110
+ function StateStack.PushState<T>(self: StateStack<T>, state: T): (() -> ())?
111
+ local data: { T } = { state }
96
112
  table.insert(self._stateStack, data)
97
113
  self:_updateState()
98
114
 
@@ -109,9 +125,9 @@ end
109
125
  @param brio Brio
110
126
  @return function -- Cleanup function
111
127
  ]=]
112
- function StateStack:PushBrio(brio)
128
+ function StateStack.PushBrio<T>(self: StateStack<T>, brio: _Brio.Brio<T>): (() -> ())?
113
129
  if brio:IsDead() then
114
- return
130
+ return nil
115
131
  end
116
132
 
117
133
  local maid, state = brio:ToMaidAndValue()
@@ -128,7 +144,7 @@ function StateStack:PushBrio(brio)
128
144
  end
129
145
  end
130
146
 
131
- function StateStack:_popState(data)
147
+ function StateStack._popState<T>(self: StateStack<T>, data: { T })
132
148
  local index = table.find(self._stateStack, data)
133
149
  if index then
134
150
  table.remove(self._stateStack, index)
@@ -138,7 +154,7 @@ function StateStack:_popState(data)
138
154
  end
139
155
  end
140
156
 
141
- function StateStack:_updateState()
157
+ function StateStack._updateState<T>(self: StateStack<T>)
142
158
  local dataContainer = self._stateStack[#self._stateStack]
143
159
  if dataContainer == nil then
144
160
  self._state.Value = self._defaultValue