@quenty/valueobject 3.6.0 → 3.6.1-canary.913a974.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 +7 -7
- package/src/Shared/ValueObject.lua +29 -3
- package/src/Shared/ValueObjectUtils.lua +17 -0
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
|
+
## [3.6.1-canary.913a974.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valueobject@3.6.0...@quenty/valueobject@3.6.1-canary.913a974.0) (2022-01-07)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add ValueObject:Observe() and StateStack:Observe() ([c10f200](https://github.com/Quenty/NevermoreEngine/commit/c10f2008508f5b44fe61c91081142ddf67ee9605))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [3.6.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valueobject@3.5.2...@quenty/valueobject@3.6.0) (2022-01-03)
|
|
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": "3.6.0",
|
|
3
|
+
"version": "3.6.1-canary.913a974.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,14 +26,14 @@
|
|
|
26
26
|
"Quenty"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@quenty/brio": "
|
|
30
|
-
"@quenty/loader": "
|
|
31
|
-
"@quenty/maid": "
|
|
32
|
-
"@quenty/rx": "
|
|
33
|
-
"@quenty/signal": "
|
|
29
|
+
"@quenty/brio": "3.6.1-canary.913a974.0",
|
|
30
|
+
"@quenty/loader": "3.2.1-canary.913a974.0",
|
|
31
|
+
"@quenty/maid": "2.0.2",
|
|
32
|
+
"@quenty/rx": "3.6.1-canary.913a974.0",
|
|
33
|
+
"@quenty/signal": "2.1.0"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "913a974e69304d8dc5aa805f2db4638a206fe89e"
|
|
39
39
|
}
|
|
@@ -8,6 +8,7 @@ local require = require(script.Parent.loader).load(script)
|
|
|
8
8
|
|
|
9
9
|
local Signal = require("Signal")
|
|
10
10
|
local Maid = require("Maid")
|
|
11
|
+
local Observable = require("Observable")
|
|
11
12
|
|
|
12
13
|
local ValueObject = {}
|
|
13
14
|
ValueObject.ClassName = "ValueObject"
|
|
@@ -24,6 +25,11 @@ function ValueObject.new(baseValue)
|
|
|
24
25
|
|
|
25
26
|
self._maid = Maid.new()
|
|
26
27
|
|
|
28
|
+
--[=[
|
|
29
|
+
Event fires when the value's object value change
|
|
30
|
+
@prop Changed Signal<T> -- fires with oldValue, newValue
|
|
31
|
+
@within ValueObject
|
|
32
|
+
]=]
|
|
27
33
|
self.Changed = Signal.new() -- :Fire(newValue, oldValue, maid)
|
|
28
34
|
self._maid:GiveTask(self.Changed)
|
|
29
35
|
|
|
@@ -40,10 +46,30 @@ function ValueObject.isValueObject(value)
|
|
|
40
46
|
end
|
|
41
47
|
|
|
42
48
|
--[=[
|
|
43
|
-
|
|
44
|
-
@
|
|
45
|
-
@within ValueObject
|
|
49
|
+
Observes the current value of the ValueObject
|
|
50
|
+
@return Observable<T>
|
|
46
51
|
]=]
|
|
52
|
+
function ValueObject:Observe()
|
|
53
|
+
return Observable.new(function(sub)
|
|
54
|
+
if not self.Destroy then
|
|
55
|
+
warn("[ValueObject.observeValue] - Connecting to dead ValueObject")
|
|
56
|
+
-- No firing, we're dead
|
|
57
|
+
sub:Complete()
|
|
58
|
+
return
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
local maid = Maid.new()
|
|
62
|
+
|
|
63
|
+
maid:GiveTask(self.Changed:Connect(function()
|
|
64
|
+
sub:Fire(self.Value)
|
|
65
|
+
end))
|
|
66
|
+
|
|
67
|
+
sub:Fire(self.Value)
|
|
68
|
+
|
|
69
|
+
return maid
|
|
70
|
+
end)
|
|
71
|
+
|
|
72
|
+
end
|
|
47
73
|
|
|
48
74
|
--[=[
|
|
49
75
|
The value of the ValueObject
|
|
@@ -12,6 +12,12 @@ local ValueObject = require("ValueObject")
|
|
|
12
12
|
|
|
13
13
|
local ValueObjectUtils = {}
|
|
14
14
|
|
|
15
|
+
--[=[
|
|
16
|
+
Syncs the value from `from` to `to`.
|
|
17
|
+
@param from ValueObject<T>
|
|
18
|
+
@param to ValueObject<T>
|
|
19
|
+
@return MaidTask
|
|
20
|
+
]=]
|
|
15
21
|
function ValueObjectUtils.syncValue(from, to)
|
|
16
22
|
local maid = Maid.new()
|
|
17
23
|
to.Value = from.Value
|
|
@@ -23,6 +29,11 @@ function ValueObjectUtils.syncValue(from, to)
|
|
|
23
29
|
return maid
|
|
24
30
|
end
|
|
25
31
|
|
|
32
|
+
--[=[
|
|
33
|
+
Observes the current value of the ValueObject
|
|
34
|
+
@param valueObject ValueObject<T>
|
|
35
|
+
@return Observable<T>
|
|
36
|
+
]=]
|
|
26
37
|
function ValueObjectUtils.observeValue(valueObject)
|
|
27
38
|
assert(ValueObject.isValueObject(valueObject), "Bad valueObject")
|
|
28
39
|
|
|
@@ -30,6 +41,7 @@ function ValueObjectUtils.observeValue(valueObject)
|
|
|
30
41
|
if not valueObject.Destroy then
|
|
31
42
|
warn("[ValueObjectUtils.observeValue] - Connecting to dead ValueObject")
|
|
32
43
|
-- No firing, we're dead
|
|
44
|
+
sub:Complete()
|
|
33
45
|
return
|
|
34
46
|
end
|
|
35
47
|
|
|
@@ -45,6 +57,11 @@ function ValueObjectUtils.observeValue(valueObject)
|
|
|
45
57
|
end)
|
|
46
58
|
end
|
|
47
59
|
|
|
60
|
+
--[=[
|
|
61
|
+
Observes the current value of the ValueObject
|
|
62
|
+
@param valueObject ValueObject<T>
|
|
63
|
+
@return Observable<Brio<T>>
|
|
64
|
+
]=]
|
|
48
65
|
function ValueObjectUtils.observeValueBrio(valueObject)
|
|
49
66
|
assert(valueObject, "Bad valueObject")
|
|
50
67
|
|