@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 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
- # [8.17.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/binder@8.16.0...@quenty/binder@8.17.0) (2023-06-05)
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": "8.17.0",
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": "^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/signal": "^2.4.0",
36
- "@quenty/valueobject": "^7.15.0"
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": "d8ad8f8567843d3867b6c06c8c57ec4493672335"
42
+ "gitHead": "903617ace784bce6cc7e0a15093ee50566bd9b54"
42
43
  }
@@ -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 Signal = require("Signal")
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._maid = Maid.new()
71
- self._tagName = tagName or error("Bad argument 'tagName', expected string")
72
- self._constructor = constructor or error("Bad argument 'constructor', expected table or function")
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
- self._maid._warning = task.delay(5, function()
82
- warn(("Binder %q is not loaded. Call :Start() on it!"):format(self._tagName))
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
@@ -117,6 +117,10 @@ function BinderProvider:Init(...)
117
117
 
118
118
  self._initMethod(self, ...)
119
119
 
120
+ for _, binder in pairs(self._binders) do
121
+ binder:Init(...)
122
+ end
123
+
120
124
  self._bindersAddedPromise:Resolve()
121
125
  end
122
126