@quenty/attributeutils 10.0.0-canary.c90a5c7.0 → 10.0.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,7 @@
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
- # [10.0.0-canary.c90a5c7.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/attributeutils@9.3.0...@quenty/attributeutils@10.0.0-canary.c90a5c7.0) (2024-01-08)
6
+ # [10.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/attributeutils@9.4.0...@quenty/attributeutils@10.0.0) (2024-01-10)
7
7
 
8
8
  **Note:** Version bump only for package @quenty/attributeutils
9
9
 
@@ -11,6 +11,17 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
11
11
 
12
12
 
13
13
 
14
+ # [9.4.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/attributeutils@9.3.0...@quenty/attributeutils@9.4.0) (2024-01-08)
15
+
16
+
17
+ ### Features
18
+
19
+ * Add RxAttributeUtils.observeAttributeKeysBrio(instance) ([896633f](https://github.com/Quenty/NevermoreEngine/commit/896633f3fef85e14f4275163c8ad37fc57f43921))
20
+
21
+
22
+
23
+
24
+
14
25
  # [9.3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/attributeutils@9.2.0...@quenty/attributeutils@9.3.0) (2023-12-28)
15
26
 
16
27
  **Note:** Version bump only for package @quenty/attributeutils
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/attributeutils",
3
- "version": "10.0.0-canary.c90a5c7.0",
3
+ "version": "10.0.0",
4
4
  "description": "Provides utility functions to work with attributes in Roblox",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -25,17 +25,17 @@
25
25
  "Quenty"
26
26
  ],
27
27
  "dependencies": {
28
- "@quenty/brio": "10.0.0-canary.c90a5c7.0",
29
- "@quenty/canceltoken": "8.0.0-canary.c90a5c7.0",
30
- "@quenty/loader": "8.0.0-canary.c90a5c7.0",
31
- "@quenty/maid": "2.6.0",
32
- "@quenty/promise": "8.0.0-canary.c90a5c7.0",
33
- "@quenty/rx": "9.0.0-canary.c90a5c7.0",
34
- "@quenty/rxsignal": "3.0.0-canary.c90a5c7.0",
35
- "@quenty/symbol": "2.2.0"
28
+ "@quenty/brio": "^10.0.0",
29
+ "@quenty/canceltoken": "^8.0.0",
30
+ "@quenty/loader": "^7.3.0",
31
+ "@quenty/maid": "^2.6.0",
32
+ "@quenty/promise": "^7.2.0",
33
+ "@quenty/rx": "^9.0.0",
34
+ "@quenty/rxsignal": "^3.0.0",
35
+ "@quenty/symbol": "^2.2.0"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "c90a5c74ac7045804ba6018fc3424e406d13f21a"
40
+ "gitHead": "bf8135721716c976201cb82133e0186ea606b166"
41
41
  }
@@ -44,6 +44,81 @@ function RxAttributeUtils.observeAttribute(instance, attributeName, defaultValue
44
44
  end)
45
45
  end
46
46
 
47
+ --[=[
48
+ Observes all the attribute keys that
49
+ @param instance Instance
50
+ @return Observable<Brio<string>>
51
+ ]=]
52
+ function RxAttributeUtils.observeAttributeKeysBrio(instance)
53
+ assert(typeof(instance) == "Instance", "Bad instance")
54
+
55
+ return Observable.new(function(sub)
56
+ local maid = Maid.new()
57
+
58
+ local attributeNameToBrio = {}
59
+
60
+ local function handleAttributeChanged(attributeName, attributeValue)
61
+ if attributeValue == nil then
62
+ local brio = attributeNameToBrio[attributeName]
63
+ if brio then
64
+ attributeNameToBrio[attributeName] = nil
65
+ maid[brio] = nil
66
+ end
67
+ else
68
+ if not attributeNameToBrio[attributeName] then
69
+ local brio = Brio.new(attributeName)
70
+ attributeNameToBrio[attributeName] = brio
71
+ maid[brio] = brio
72
+ sub:Fire(brio)
73
+ end
74
+ end
75
+ end
76
+
77
+ maid:GiveTask(instance.AttributeChanged:Connect(function(attributeName)
78
+ handleAttributeChanged(attributeName, instance:GetAttribute(attributeName))
79
+ end))
80
+
81
+ for attributeName, attributeValue in pairs(instance:GetAttributes()) do
82
+ if not sub:IsPending() then
83
+ break
84
+ end
85
+
86
+ -- TODO: Maybe we technically need to requery here but it's expensive
87
+ handleAttributeChanged(attributeName, attributeValue)
88
+ end
89
+
90
+ return maid
91
+ end)
92
+ end
93
+
94
+ --[=[
95
+ Observes all the attribute keys for an instance
96
+
97
+ @param instance Instance
98
+ @return Observable<string>
99
+ ]=]
100
+ function RxAttributeUtils.observeAttributeKeys(instance)
101
+ assert(typeof(instance) == "Instance", "Bad instance")
102
+
103
+ return Observable.new(function(sub)
104
+ local maid = Maid.new()
105
+
106
+ maid:GiveTask(instance.AttributeChanged:Connect(function(attribute)
107
+ sub:Fire(attribute)
108
+ end))
109
+
110
+ for attribute, _ in pairs(instance:GetAttributes()) do
111
+ if not sub:IsPending() then
112
+ break
113
+ end
114
+
115
+ sub:Fire(attribute)
116
+ end
117
+
118
+ return maid
119
+ end)
120
+ end
121
+
47
122
  --[=[
48
123
  Observes an attribute on an instance with a conditional statement.
49
124
  @param instance Instance