@quenty/binder 8.17.0 → 9.0.0-canary.367.903617a.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 +1 -1
- package/package.json +12 -11
- package/src/Shared/Binder.lua +70 -14
- package/src/Shared/BinderProvider.lua +4 -0
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
|
-
# [
|
|
6
|
+
# [9.0.0-canary.367.903617a.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/binder@8.16.0...@quenty/binder@9.0.0-canary.367.903617a.0) (2023-06-09)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @quenty/binder
|
|
9
9
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/binder",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-canary.367.903617a.0",
|
|
4
4
|
"description": "Utility object to Bind a class to Roblox object, and associated helper methods",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -25,18 +25,19 @@
|
|
|
25
25
|
"Quenty"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@quenty/baseobject": "
|
|
29
|
-
"@quenty/brio": "
|
|
30
|
-
"@quenty/instanceutils": "
|
|
31
|
-
"@quenty/linkutils": "
|
|
32
|
-
"@quenty/loader": "
|
|
33
|
-
"@quenty/maid": "
|
|
34
|
-
"@quenty/promise": "
|
|
35
|
-
"@quenty/
|
|
36
|
-
"@quenty/
|
|
28
|
+
"@quenty/baseobject": "6.2.1",
|
|
29
|
+
"@quenty/brio": "8.13.0",
|
|
30
|
+
"@quenty/instanceutils": "7.14.0",
|
|
31
|
+
"@quenty/linkutils": "7.14.0",
|
|
32
|
+
"@quenty/loader": "6.2.1",
|
|
33
|
+
"@quenty/maid": "2.5.0",
|
|
34
|
+
"@quenty/promise": "6.5.0",
|
|
35
|
+
"@quenty/rx": "7.11.0",
|
|
36
|
+
"@quenty/signal": "2.4.0",
|
|
37
|
+
"@quenty/valueobject": "8.0.0-canary.367.903617a.0"
|
|
37
38
|
},
|
|
38
39
|
"publishConfig": {
|
|
39
40
|
"access": "public"
|
|
40
41
|
},
|
|
41
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "903617ace784bce6cc7e0a15093ee50566bd9b54"
|
|
42
43
|
}
|
package/src/Shared/Binder.lua
CHANGED
|
@@ -31,8 +31,9 @@ local CollectionService = game:GetService("CollectionService")
|
|
|
31
31
|
|
|
32
32
|
local Maid = require("Maid")
|
|
33
33
|
local MaidTaskUtils = require("MaidTaskUtils")
|
|
34
|
-
local
|
|
34
|
+
local Observable = require("Observable")
|
|
35
35
|
local promiseBoundClass = require("promiseBoundClass")
|
|
36
|
+
local Signal = require("Signal")
|
|
36
37
|
|
|
37
38
|
local Binder = {}
|
|
38
39
|
Binder.__index = Binder
|
|
@@ -67,20 +68,13 @@ Binder.ClassName = "Binder"
|
|
|
67
68
|
function Binder.new(tagName, constructor, ...)
|
|
68
69
|
local self = setmetatable({}, Binder)
|
|
69
70
|
|
|
70
|
-
self.
|
|
71
|
-
self.
|
|
72
|
-
self.
|
|
73
|
-
|
|
74
|
-
self._instToClass = {} -- [inst] = class
|
|
75
|
-
self._allClassSet = {} -- [class] = true
|
|
76
|
-
self._pendingInstSet = {} -- [inst] = true
|
|
77
|
-
|
|
78
|
-
self._listeners = {} -- [inst] = callback
|
|
79
|
-
self._args = {...}
|
|
71
|
+
self._tagName = assert(tagName, "Bad argument 'tagName', expected string")
|
|
72
|
+
self._constructor = assert(constructor, "Bad argument 'constructor', expected table or function")
|
|
73
|
+
self.ServiceName = "Binder" .. self._tagName
|
|
80
74
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
end
|
|
75
|
+
if select("#", ...) > 0 then
|
|
76
|
+
self._args = { ... }
|
|
77
|
+
end
|
|
84
78
|
|
|
85
79
|
return self
|
|
86
80
|
end
|
|
@@ -111,10 +105,46 @@ function Binder.isBinder(value)
|
|
|
111
105
|
and type(value.Destroy) == "function"
|
|
112
106
|
end
|
|
113
107
|
|
|
108
|
+
--[=[
|
|
109
|
+
Initializes the Binder. Designed to be done via ServiceBag.
|
|
110
|
+
|
|
111
|
+
@param ... any
|
|
112
|
+
]=]
|
|
113
|
+
function Binder:Init(...)
|
|
114
|
+
if self._initialized then
|
|
115
|
+
return
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
self._initialized = true
|
|
119
|
+
self._maid = Maid.new()
|
|
120
|
+
|
|
121
|
+
self._instToClass = {} -- [inst] = class
|
|
122
|
+
self._allClassSet = {} -- [class] = true
|
|
123
|
+
self._pendingInstSet = {} -- [inst] = true
|
|
124
|
+
|
|
125
|
+
self._listeners = {} -- [inst] = callback
|
|
126
|
+
|
|
127
|
+
if select("#", ...) > 0 then
|
|
128
|
+
if not self._args then
|
|
129
|
+
self._args = {...}
|
|
130
|
+
else
|
|
131
|
+
warn("[Binder.Init] - Matching args")
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
self._maid._warning = task.delay(5, function()
|
|
136
|
+
warn(("Binder %q is not loaded. Call :Start() on it!"):format(self._tagName))
|
|
137
|
+
end)
|
|
138
|
+
end
|
|
139
|
+
|
|
114
140
|
--[=[
|
|
115
141
|
Listens for new instances and connects to the GetInstanceAddedSignal() and removed signal!
|
|
116
142
|
]=]
|
|
117
143
|
function Binder:Start()
|
|
144
|
+
if not self._initialized then
|
|
145
|
+
self:Init()
|
|
146
|
+
end
|
|
147
|
+
|
|
118
148
|
if self._loaded then
|
|
119
149
|
return
|
|
120
150
|
end
|
|
@@ -151,9 +181,35 @@ function Binder:GetConstructor()
|
|
|
151
181
|
return self._constructor
|
|
152
182
|
end
|
|
153
183
|
|
|
184
|
+
--[=[
|
|
185
|
+
Observes the current value of the instance
|
|
186
|
+
|
|
187
|
+
@param instance Instance
|
|
188
|
+
@return Observable<Instance | nil>
|
|
189
|
+
]=]
|
|
190
|
+
function Binder:Observe(instance)
|
|
191
|
+
assert(typeof(instance) == "Instance", "Bad instance")
|
|
192
|
+
|
|
193
|
+
return Observable.new(function(sub)
|
|
194
|
+
local maid = Maid.new()
|
|
195
|
+
|
|
196
|
+
maid:GiveTask(self:ObserveInstance(instance, function(...)
|
|
197
|
+
sub:Fire(...)
|
|
198
|
+
end))
|
|
199
|
+
sub:Fire(self:Get(instance))
|
|
200
|
+
|
|
201
|
+
return maid
|
|
202
|
+
end)
|
|
203
|
+
end
|
|
204
|
+
|
|
154
205
|
--[=[
|
|
155
206
|
Fired when added, and then after removal, but before destroy!
|
|
156
207
|
|
|
208
|
+
```info
|
|
209
|
+
This is before [Rx] so it doesn't follow the same Rx pattern. See [Binder.Observe] for
|
|
210
|
+
an [Rx] compatible interface.
|
|
211
|
+
```
|
|
212
|
+
|
|
157
213
|
@param inst Instance
|
|
158
214
|
@param callback function
|
|
159
215
|
@return function -- Cleanup function
|