@quenty/valueobject 13.13.0 → 13.13.1-canary.522.1d2faf4.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 +11 -0
- package/package.json +9 -9
- package/src/Shared/ValueObject.lua +17 -3
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
|
+
## [13.13.1-canary.522.1d2faf4.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valueobject@13.13.0...@quenty/valueobject@13.13.1-canary.522.1d2faf4.0) (2024-12-03)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add :SetValue() behavior to cleanup past mounted sub and return a function to unset the value ([03fd05a](https://github.com/Quenty/NevermoreEngine/commit/03fd05aaefbeccc6cc26359239876e1a39569bc1))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [13.13.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valueobject@13.12.0...@quenty/valueobject@13.13.0) (2024-11-13)
|
|
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": "13.13.0",
|
|
3
|
+
"version": "13.13.1-canary.522.1d2faf4.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",
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
"Quenty"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@quenty/brio": "
|
|
30
|
-
"@quenty/ducktype": "
|
|
31
|
-
"@quenty/loader": "
|
|
32
|
-
"@quenty/maid": "
|
|
33
|
-
"@quenty/rx": "
|
|
34
|
-
"@quenty/signal": "
|
|
35
|
-
"@quenty/valuebaseutils": "
|
|
29
|
+
"@quenty/brio": "14.13.1-canary.522.1d2faf4.0",
|
|
30
|
+
"@quenty/ducktype": "5.7.1",
|
|
31
|
+
"@quenty/loader": "10.7.1",
|
|
32
|
+
"@quenty/maid": "3.4.0",
|
|
33
|
+
"@quenty/rx": "13.13.1-canary.522.1d2faf4.0",
|
|
34
|
+
"@quenty/signal": "7.9.0",
|
|
35
|
+
"@quenty/valuebaseutils": "13.13.1-canary.522.1d2faf4.0"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "1d2faf48e778ada6f57aecb8000c7c6c76ac33cd"
|
|
41
41
|
}
|
|
@@ -29,6 +29,7 @@ ValueObject.ClassName = "ValueObject"
|
|
|
29
29
|
function ValueObject.new(baseValue, checkType)
|
|
30
30
|
local self = setmetatable({
|
|
31
31
|
_value = baseValue;
|
|
32
|
+
_default = baseValue;
|
|
32
33
|
_checkType = checkType;
|
|
33
34
|
}, ValueObject)
|
|
34
35
|
|
|
@@ -111,7 +112,7 @@ function ValueObject:Mount(value)
|
|
|
111
112
|
self:_cleanupLastMountedSub()
|
|
112
113
|
|
|
113
114
|
local sub = observable:Subscribe(function(...)
|
|
114
|
-
self
|
|
115
|
+
ValueObject._applyValue(self, ...)
|
|
115
116
|
end)
|
|
116
117
|
|
|
117
118
|
rawset(self, "_lastMountedSub", sub)
|
|
@@ -124,7 +125,7 @@ function ValueObject:Mount(value)
|
|
|
124
125
|
else
|
|
125
126
|
self:_cleanupLastMountedSub()
|
|
126
127
|
|
|
127
|
-
self
|
|
128
|
+
ValueObject._applyValue(self, value)
|
|
128
129
|
|
|
129
130
|
return EMPTY_FUNCTION
|
|
130
131
|
end
|
|
@@ -234,8 +235,21 @@ end
|
|
|
234
235
|
|
|
235
236
|
@param value T
|
|
236
237
|
@param ... any -- Additional args. Can be used to pass event changing state args with value
|
|
238
|
+
@return () -> () -- Cleanup
|
|
237
239
|
]=]
|
|
238
240
|
function ValueObject:SetValue(value, ...)
|
|
241
|
+
self:_cleanupLastMountedSub()
|
|
242
|
+
|
|
243
|
+
ValueObject._applyValue(self, value, ...)
|
|
244
|
+
|
|
245
|
+
return function()
|
|
246
|
+
if rawget(self, "_value") == value then
|
|
247
|
+
ValueObject._applyValue(self, rawget(self, "_default"))
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
function ValueObject:_applyValue(value, ...)
|
|
239
253
|
local previous = rawget(self, "_value")
|
|
240
254
|
local checkType = rawget(self, "_checkType")
|
|
241
255
|
|
|
@@ -298,7 +312,7 @@ end
|
|
|
298
312
|
function ValueObject:__newindex(index, value)
|
|
299
313
|
if index == "Value" then
|
|
300
314
|
-- Avoid deoptimization
|
|
301
|
-
ValueObject.
|
|
315
|
+
ValueObject._applyValue(self, value)
|
|
302
316
|
elseif index == "LastEventContext" or ValueObject[index] then
|
|
303
317
|
error(string.format("%q cannot be set in ValueObject", tostring(index)))
|
|
304
318
|
else
|