@quenty/valueobject 4.0.0-canary.236.5597d0a.0 → 4.1.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,7 +3,74 @@
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
- # [4.0.0-canary.236.5597d0a.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valueobject@3.4.0...@quenty/valueobject@4.0.0-canary.236.5597d0a.0) (2021-12-18)
6
+ # [4.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valueobject@4.0.0...@quenty/valueobject@4.1.0) (2022-03-10)
7
+
8
+ **Note:** Version bump only for package @quenty/valueobject
9
+
10
+
11
+
12
+
13
+
14
+ # [4.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valueobject@3.8.0...@quenty/valueobject@4.0.0) (2022-03-06)
15
+
16
+ **Note:** Version bump only for package @quenty/valueobject
17
+
18
+
19
+
20
+
21
+
22
+ # [3.8.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valueobject@3.7.1...@quenty/valueobject@3.8.0) (2022-01-17)
23
+
24
+ **Note:** Version bump only for package @quenty/valueobject
25
+
26
+
27
+
28
+
29
+
30
+ ## [3.7.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valueobject@3.7.0...@quenty/valueobject@3.7.1) (2022-01-16)
31
+
32
+ **Note:** Version bump only for package @quenty/valueobject
33
+
34
+
35
+
36
+
37
+
38
+ # [3.7.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valueobject@3.6.0...@quenty/valueobject@3.7.0) (2022-01-07)
39
+
40
+
41
+ ### Features
42
+
43
+ * Add ValueObject:Observe() and StateStack:Observe() ([91af9f2](https://github.com/Quenty/NevermoreEngine/commit/91af9f25e41faddeaa2f02f31ddfb8b145d01068))
44
+
45
+
46
+
47
+
48
+
49
+ # [3.6.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valueobject@3.5.2...@quenty/valueobject@3.6.0) (2022-01-03)
50
+
51
+ **Note:** Version bump only for package @quenty/valueobject
52
+
53
+
54
+
55
+
56
+
57
+ ## [3.5.2](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valueobject@3.5.1...@quenty/valueobject@3.5.2) (2021-12-30)
58
+
59
+ **Note:** Version bump only for package @quenty/valueobject
60
+
61
+
62
+
63
+
64
+
65
+ ## [3.5.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valueobject@3.5.0...@quenty/valueobject@3.5.1) (2021-12-30)
66
+
67
+ **Note:** Version bump only for package @quenty/valueobject
68
+
69
+
70
+
71
+
72
+
73
+ # [3.5.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/valueobject@3.4.0...@quenty/valueobject@3.5.0) (2021-12-18)
7
74
 
8
75
  **Note:** Version bump only for package @quenty/valueobject
9
76
 
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  ## ValueObject
2
2
  <div align="center">
3
- <a href="http://quenty.github.io/api/">
4
- <img src="https://img.shields.io/badge/docs-website-green.svg" alt="Documentation" />
3
+ <a href="http://quenty.github.io/NevermoreEngine/">
4
+ <img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
5
5
  </a>
6
6
  <a href="https://discord.gg/mhtGUS8">
7
- <img src="https://img.shields.io/badge/discord-nevermore-blue.svg" alt="Discord" />
7
+ <img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
8
8
  </a>
9
9
  <a href="https://github.com/Quenty/NevermoreEngine/actions">
10
10
  <img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
@@ -13,6 +13,8 @@
13
13
 
14
14
  To work like value objects in Roblox and track a single item with .Changed events. The motivation here is to keep it simple to work with an encapsulated value. Instead of exposing an `IPropertyChanged` interface like C# might do, we instead expose objects with .Changed that are encapsulated within the object in question.
15
15
 
16
+ <div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/ValueObject">View docs →</a></div>
17
+
16
18
  ## Installation
17
19
  ```
18
20
  npm install @quenty/valueobject --save
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/valueobject",
3
- "version": "4.0.0-canary.236.5597d0a.0",
3
+ "version": "4.1.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": "4.0.0-canary.236.5597d0a.0",
30
- "@quenty/loader": "3.1.1",
31
- "@quenty/maid": "2.0.1",
32
- "@quenty/rx": "4.0.0-canary.236.5597d0a.0",
33
- "@quenty/signal": "2.0.0"
29
+ "@quenty/brio": "^5.1.0",
30
+ "@quenty/loader": "^4.0.0",
31
+ "@quenty/maid": "^2.2.0",
32
+ "@quenty/rx": "^4.1.0",
33
+ "@quenty/signal": "^2.1.0"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "5597d0abdadd88f369f1401a558a8d6d1a1c5aab"
38
+ "gitHead": "0797de955876b050fb24875de0423453e268b2ce"
39
39
  }
@@ -1,27 +1,23 @@
1
- --- To work like value objects in Roblox and track a single item,
2
- -- with `.Changed` events
3
- -- @classmod ValueObject
1
+ --[=[
2
+ To work like value objects in Roblox and track a single item,
3
+ with `.Changed` events
4
+ @class ValueObject
5
+ ]=]
4
6
 
5
7
  local require = require(script.Parent.loader).load(script)
6
8
 
7
9
  local Signal = require("Signal")
8
10
  local Maid = require("Maid")
11
+ local Observable = require("Observable")
9
12
 
10
13
  local ValueObject = {}
11
14
  ValueObject.ClassName = "ValueObject"
12
15
 
13
- --- The value of the ValueObject
14
- -- @tfield Variant Value
15
-
16
- --- Event fires when the value's object value change
17
- -- @signal Changed
18
- -- @tparam Variant newValue The new value
19
- -- @tparam Variant oldValue The old value
20
-
21
-
22
- --- Constructs a new value object
23
- -- @constructor
24
- -- @treturn ValueObject
16
+ --[=[
17
+ Constructs a new value object
18
+ @param baseValue T
19
+ @return ValueObject
20
+ ]=]
25
21
  function ValueObject.new(baseValue)
26
22
  local self = {}
27
23
 
@@ -29,16 +25,57 @@ function ValueObject.new(baseValue)
29
25
 
30
26
  self._maid = Maid.new()
31
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
+ ]=]
32
33
  self.Changed = Signal.new() -- :Fire(newValue, oldValue, maid)
33
34
  self._maid:GiveTask(self.Changed)
34
35
 
35
36
  return setmetatable(self, ValueObject)
36
37
  end
37
38
 
39
+ --[=[
40
+ Returns whether the object is a ValueObject class
41
+ @param value any
42
+ @return boolean
43
+ ]=]
38
44
  function ValueObject.isValueObject(value)
39
45
  return type(value) == "table" and getmetatable(value) == ValueObject
40
46
  end
41
47
 
48
+ --[=[
49
+ Observes the current value of the ValueObject
50
+ @return Observable<T>
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
73
+
74
+ --[=[
75
+ The value of the ValueObject
76
+ @prop Value T
77
+ @within ValueObject
78
+ ]=]
42
79
  function ValueObject:__index(index)
43
80
  if index == "Value" then
44
81
  return self._value
@@ -68,7 +105,11 @@ function ValueObject:__newindex(index, value)
68
105
  end
69
106
  end
70
107
 
71
- --- Forces the value to be nil on cleanup, cleans up the Maid
108
+ --[=[
109
+ Forces the value to be nil on cleanup, cleans up the Maid
110
+
111
+ Does not fire the event since 3.5.0
112
+ ]=]
72
113
  function ValueObject:Destroy()
73
114
  rawset(self, "_value", nil)
74
115
  self._maid:DoCleaning()
@@ -1,5 +1,7 @@
1
- --- Utils that work with Roblox Value objects (and also ValueObject)
2
- -- @module ValueObjectUtils
1
+ --[=[
2
+ Utils that work with Roblox Value objects (and also ValueObject)
3
+ @class ValueObjectUtils
4
+ ]=]
3
5
 
4
6
  local require = require(script.Parent.loader).load(script)
5
7
 
@@ -10,6 +12,12 @@ local ValueObject = require("ValueObject")
10
12
 
11
13
  local ValueObjectUtils = {}
12
14
 
15
+ --[=[
16
+ Syncs the value from `from` to `to`.
17
+ @param from ValueObject<T>
18
+ @param to ValueObject<T>
19
+ @return MaidTask
20
+ ]=]
13
21
  function ValueObjectUtils.syncValue(from, to)
14
22
  local maid = Maid.new()
15
23
  to.Value = from.Value
@@ -21,6 +29,11 @@ function ValueObjectUtils.syncValue(from, to)
21
29
  return maid
22
30
  end
23
31
 
32
+ --[=[
33
+ Observes the current value of the ValueObject
34
+ @param valueObject ValueObject<T>
35
+ @return Observable<T>
36
+ ]=]
24
37
  function ValueObjectUtils.observeValue(valueObject)
25
38
  assert(ValueObject.isValueObject(valueObject), "Bad valueObject")
26
39
 
@@ -28,6 +41,7 @@ function ValueObjectUtils.observeValue(valueObject)
28
41
  if not valueObject.Destroy then
29
42
  warn("[ValueObjectUtils.observeValue] - Connecting to dead ValueObject")
30
43
  -- No firing, we're dead
44
+ sub:Complete()
31
45
  return
32
46
  end
33
47
 
@@ -43,6 +57,11 @@ function ValueObjectUtils.observeValue(valueObject)
43
57
  end)
44
58
  end
45
59
 
60
+ --[=[
61
+ Observes the current value of the ValueObject
62
+ @param valueObject ValueObject<T>
63
+ @return Observable<Brio<T>>
64
+ ]=]
46
65
  function ValueObjectUtils.observeValueBrio(valueObject)
47
66
  assert(valueObject, "Bad valueObject")
48
67
 
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "ValueObject",
3
+ "tree": {
4
+ "$className": "DataModel",
5
+ "ServerScriptService": {
6
+ "valueobject": {
7
+ "$path": ".."
8
+ }
9
+ }
10
+ }
11
+ }