@quenty/valueobject 7.18.0 → 7.19.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,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
+ # [7.19.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valueobject@7.18.0...@quenty/valueobject@7.19.0) (2023-07-23)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add ValueObject:ObserveBrio(condition) ([2d3766a](https://github.com/Quenty/NevermoreEngine/commit/2d3766a535706d45ce5d217a7cdc81daa198f1f7))
12
+
13
+
14
+
15
+
16
+
6
17
  # [7.18.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valueobject@7.17.0...@quenty/valueobject@7.18.0) (2023-07-15)
7
18
 
8
19
  **Note:** Version bump only for package @quenty/valueobject
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/valueobject",
3
- "version": "7.18.0",
3
+ "version": "7.19.0",
4
4
  "description": "To work like value objects in Roblox and track a single item with .Changed events",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -36,5 +36,5 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "af7a623f58fe7ec96b47c80e385b71f820fd4cb8"
39
+ "gitHead": "c1fbe93a0a20b5c0c4b9ffbbac771926b07ac251"
40
40
  }
@@ -11,6 +11,7 @@ local Maid = require("Maid")
11
11
  local Observable = require("Observable")
12
12
  local ValueBaseUtils = require("ValueBaseUtils")
13
13
  local RxValueBaseUtils = require("RxValueBaseUtils")
14
+ local Brio = require("Brio")
14
15
 
15
16
  local EMPTY_FUNCTION = function() end
16
17
 
@@ -164,6 +165,50 @@ function ValueObject:Observe()
164
165
  end)
165
166
  end
166
167
 
168
+ --[=[
169
+ Observes the value as a brio. The condition defaults to truthy or nil.
170
+
171
+ @param condition function | nil -- optional
172
+ @return Observable<Brio<T>>
173
+ ]=]
174
+ function ValueObject:ObserveBrio(condition)
175
+ assert(type(condition) == "function" or condition == nil, "Bad condition")
176
+
177
+ return Observable.new(function(sub)
178
+ if not self.Destroy then
179
+ warn("[ValueObject.observeValue] - Connecting to dead ValueObject")
180
+ -- No firing, we're dead
181
+ sub:Complete()
182
+ return
183
+ end
184
+
185
+ local maid = Maid.new()
186
+
187
+ local function handleNewValue(newValue, ...)
188
+ if not condition or condition(newValue) then
189
+ local brio = Brio.new(newValue, ...)
190
+ maid._current = brio
191
+ sub:Fire(brio)
192
+ else
193
+ maid._current = nil
194
+ end
195
+ end
196
+
197
+ maid:GiveTask(self.Changed:Connect(function(newValue, _, _, ...)
198
+ handleNewValue(newValue, ...)
199
+ end))
200
+
201
+ local args = rawget(self, "_lastEventContext")
202
+ if args then
203
+ handleNewValue(self.Value, table.unpack(args, 1, args.n))
204
+ else
205
+ handleNewValue(self.Value)
206
+ end
207
+
208
+ return maid
209
+ end)
210
+ end
211
+
167
212
  --[=[
168
213
  Allows you to set a value, and provide additional event context for the actual change.
169
214
  For example, you might do.