Skip to content

Commit 08af04f

Browse files
committed
Modified types for Binder
1 parent 4aaaeb6 commit 08af04f

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/index.d.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ declare namespace Binder {
1313
}
1414

1515
interface Binder<T extends Binder.BinderClass = Binder.BinderClass> {
16+
/** ClassName of Binder */
17+
readonly ClassName: string;
18+
1619
/** Listens for new instances and connects to the GetInstanceAddedSignal() and removed signal! */
1720
Start(): void;
1821

@@ -22,6 +25,15 @@ interface Binder<T extends Binder.BinderClass = Binder.BinderClass> {
2225
/** Returns whatever was set for the construtor. Used for meta-analysis of the binder, such as extracting new */
2326
GetConstructor(): Binder.BinderClassConstructor<T>;
2427

28+
/** `Binder.ObserveInstance()` with Promise returned */
29+
Promise(inst: Instance): Promise<T>;
30+
31+
/**
32+
* Sets descendants whitelist to only binds object if that object is descendant of whitelisted one
33+
* @param descendants Whilelisted descendants
34+
*/
35+
SetDescendantsWhitelist(descendants: Instance[]): void;
36+
2537
/**
2638
* Fired when added, and then after removal, but before destroy!
2739
* @param inst Instance
@@ -36,7 +48,7 @@ interface Binder<T extends Binder.BinderClass = Binder.BinderClass> {
3648
* const birdBinder = new Binder("Bird", require(path.to.Bird) as typeof Bird);
3749
* birdBinder.GetClassAddedSignal().Connect(bird => {
3850
* // Make the bird squack when it's first spawned
39-
* bird.Squack();
51+
* bird.Squack();
4052
* });
4153
*
4254
* // Load all birds
@@ -62,10 +74,6 @@ interface Binder<T extends Binder.BinderClass = Binder.BinderClass> {
6274
*/
6375
GetAll(): T[];
6476

65-
/**
66-
* for (const [classObj] of thatBinder.GetAllSet()) {}
67-
*/
68-
6977
/**
7078
* Faster method to get all items in a binder
7179
*
@@ -83,7 +91,7 @@ interface Binder<T extends Binder.BinderClass = Binder.BinderClass> {
8391
*
8492
* birdBinder.Init()
8593
*/
86-
GetAllSet(): Array<[T, boolean]>;
94+
GetAllSet(): Map<T, true>;
8795

8896
/**
8997
* Binds an instance to this binder using collection service and attempts
@@ -101,6 +109,7 @@ interface Binder<T extends Binder.BinderClass = Binder.BinderClass> {
101109
* See ``.Bind()``
102110
*
103111
* Acknowledges the risk of doing this on the client.
112+
*
104113
* Using this acknowledges that we're intentionally binding on a safe client object,
105114
* i.e. one without replication. If another tag is changed on this instance, this tag will be lost/changed.
106115
*/
@@ -141,7 +150,7 @@ interface BinderConstructor {
141150
* @param value
142151
* @returns boolean
143152
*/
144-
isBinder: <T extends Binder.BinderClass>(object: unknown) => object is Binder<T>;
153+
isBinder: <T extends Binder.BinderClass = Binder.BinderClass>(object: unknown) => object is Binder<T>;
145154
}
146155

147156
/**

src/init.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ function Binder:Start()
110110
end))
111111
end
112112

113+
--- Sets descendants whitelist to only binds object if that object is descendant of whitelisted one
114+
-- @param descendants Whilelisted descendants
113115
function Binder:SetDescendantsWhitelist(descendants)
114-
assert(typeof(descendants) == "table", "Bad inst'")
116+
assert(typeof(descendants) == "table", "Bad table")
115117
if self._whitelist ~= nil then
116118
warn("[Binder.SetDescendantsWhitelist]: Attempt to override descendants whitelist")
117119
return
@@ -270,12 +272,13 @@ function Binder:UnbindClient(inst)
270272
CollectionService:RemoveTag(inst, self._tagName)
271273
end
272274

273-
--- Returns a version of the clas
275+
--- Returns a version of the class, if it exists
274276
function Binder:Get(inst)
275277
assert(typeof(inst) == "Instance", "Argument 'inst' is not an Instance")
276278
return self._instToClass[inst]
277279
end
278280

281+
--- Binder:ObserveInstance() with Promise returned
279282
function Binder:Promise(inst)
280283
assert(typeof(inst) == "Instance", "Argument 'inst' is not an Instance")
281284
return promiseBoundClass(self, inst)

0 commit comments

Comments
 (0)