@quenty/attributeutils 8.8.0 → 8.9.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/LICENSE.md +1 -1
- package/package.json +6 -4
- package/src/Shared/AttributeUtils.lua +54 -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
|
+
# [8.9.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/attributeutils@8.8.0...@quenty/attributeutils@8.9.0) (2023-03-31)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add AttributeUtils.promiseAttribute(instance, attributeName, predicate, cancelToken) ([cf98166](https://github.com/Quenty/NevermoreEngine/commit/cf98166007c7dd2b79946701cd17fb7f89390bae))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [8.8.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/attributeutils@8.7.0...@quenty/attributeutils@8.8.0) (2023-03-05)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @quenty/attributeutils
|
package/LICENSE.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/attributeutils",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.9.0",
|
|
4
4
|
"description": "Provides utility functions to work with attributes in Roblox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -25,14 +25,16 @@
|
|
|
25
25
|
"Quenty"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@quenty/brio": "^8.
|
|
28
|
+
"@quenty/brio": "^8.8.0",
|
|
29
|
+
"@quenty/canceltoken": "^6.4.0",
|
|
29
30
|
"@quenty/loader": "^6.2.0",
|
|
30
31
|
"@quenty/maid": "^2.5.0",
|
|
31
|
-
"@quenty/
|
|
32
|
+
"@quenty/promise": "^6.4.0",
|
|
33
|
+
"@quenty/rx": "^7.8.0",
|
|
32
34
|
"@quenty/symbol": "^2.2.0"
|
|
33
35
|
},
|
|
34
36
|
"publishConfig": {
|
|
35
37
|
"access": "public"
|
|
36
38
|
},
|
|
37
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "2a1c35a8d2e90b291a83a6e2def0ec69f3f24837"
|
|
38
40
|
}
|
|
@@ -8,6 +8,12 @@ local require = require(script.Parent.loader).load(script)
|
|
|
8
8
|
local RunService = game:GetService("RunService")
|
|
9
9
|
|
|
10
10
|
local Maid = require("Maid")
|
|
11
|
+
local Promise = require("Promise")
|
|
12
|
+
local CancelToken = require("CancelToken")
|
|
13
|
+
|
|
14
|
+
local DEFAULT_PREDICATE = function(value)
|
|
15
|
+
return value ~= nil
|
|
16
|
+
end
|
|
11
17
|
|
|
12
18
|
local AttributeUtils = {}
|
|
13
19
|
|
|
@@ -45,6 +51,54 @@ function AttributeUtils.isValidAttributeType(valueType)
|
|
|
45
51
|
return VALID_ATTRIBUTE_TYPES[valueType] == true
|
|
46
52
|
end
|
|
47
53
|
|
|
54
|
+
--[=[
|
|
55
|
+
Promises attribute value fits predicate
|
|
56
|
+
|
|
57
|
+
@param instance Instance
|
|
58
|
+
@param attributeName string
|
|
59
|
+
@param predicate function | nil
|
|
60
|
+
@param cancelToken CancelToken
|
|
61
|
+
@return Promise<any>
|
|
62
|
+
]=]
|
|
63
|
+
function AttributeUtils.promiseAttribute(instance, attributeName, predicate, cancelToken)
|
|
64
|
+
assert(typeof(instance) == "Instance", "Bad instance")
|
|
65
|
+
assert(type(attributeName) == "string", "Bad attributeName")
|
|
66
|
+
assert(CancelToken.isCancelToken(cancelToken) or cancelToken == nil, "Bad cancelToken")
|
|
67
|
+
|
|
68
|
+
predicate = predicate or DEFAULT_PREDICATE
|
|
69
|
+
|
|
70
|
+
do
|
|
71
|
+
local attributeValue = instance:GetAttribute(attributeName)
|
|
72
|
+
if predicate(attributeValue) then
|
|
73
|
+
return Promise.resolved(attributeValue)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
local promise = Promise.new()
|
|
78
|
+
local maid = Maid.new()
|
|
79
|
+
maid:GiveTask(promise)
|
|
80
|
+
|
|
81
|
+
if cancelToken then
|
|
82
|
+
maid:GiveTask(cancelToken.Cancelled:Connect(function()
|
|
83
|
+
promise:Reject()
|
|
84
|
+
end))
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
maid:GiveTask(instance:GetAttributeChangedSignal(attributeName):Connect(function()
|
|
88
|
+
local attributeValue = instance:GetAttribute(attributeName)
|
|
89
|
+
if predicate(attributeValue) then
|
|
90
|
+
promise:Resolve(attributeValue)
|
|
91
|
+
end
|
|
92
|
+
end))
|
|
93
|
+
|
|
94
|
+
promise:Finally(function()
|
|
95
|
+
maid:DoCleaning()
|
|
96
|
+
end)
|
|
97
|
+
|
|
98
|
+
return promise
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
|
|
48
102
|
--[=[
|
|
49
103
|
Whenever the attribute is true, the binder will be bound, and when the
|
|
50
104
|
binder is bound, the attribute will be true.
|