File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,6 +42,8 @@ to determine what should happen.
4242- if ` function ` , it is called
4343- ...else if ` {destroy: (self) -> ()} ` , ` :destroy() ` is called
4444- ...else if ` {Destroy: (self) -> ()} ` , ` :Destroy() ` is called
45+ - ...else if ` {disconnect: (self) -> ()} ` , ` :disconnect() ` is called
46+ - ...else if ` {Disconnect: (self) -> ()} ` , ` :Disconnect() ` is called
4547- ...else if ` {any} ` , ` doCleanup ` is called on all members
4648
4749When Fusion is running inside of Roblox:
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ export type Task =
1616 | () -> ()
1717 | {destroy : (self ) -> ()}
1818 | {Destroy : (self ) -> ()}
19+ | {disconnect : (self ) -> ()}
20+ | {Disconnect : (self ) -> ()}
1921 | {Task }
2022```
2123Types which [ ` doCleanup ` ] ( ../../members/docleanup ) has defined behaviour for.
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ Scopes passed to `doCleanup` can contain:
7777- Roblox instances to destroy
7878- Roblox event connections to disconnect
7979- Your own objects with ` :destroy() ` or ` :Destroy() ` methods to be called
80+ - Your own objects with ` :disconnect() ` or ` :Disconnect() ` methods to be called
8081- Other nested scopes to be cleaned up
8182
8283You can add these manually using ` table.insert ` if you need custom behaviour,
Original file line number Diff line number Diff line change @@ -41,7 +41,14 @@ local function doCleanup(
4141 task ()
4242
4343 elseif typeof (task ) == "table" then
44- local task = (task :: any ) :: {Destroy : (...unknown ) -> (...unknown )? , destroy : (...unknown ) -> (...unknown )? }
44+ local task = (
45+ task :: any
46+ ) :: {
47+ Destroy : (...unknown ) -> ...unknown ? ,
48+ destroy : (...unknown ) -> ...unknown ? ,
49+ Disconnect : (...unknown ) -> ...unknown ? ,
50+ disconnect : (...unknown ) -> ...unknown ? ,
51+ }
4552
4653 -- case 4: destroy() function
4754 if typeof (task .destroy ) == "function" then
@@ -65,6 +72,16 @@ local function doCleanup(
6572 end
6673
6774 ExternalDebug .untrackScope (task )
75+
76+ -- case 7: Disconnect() function
77+ elseif typeof (task .Disconnect ) == "function" then
78+ local task = (task :: any ) :: { Disconnect : (...unknown ) -> ...unknown }
79+ task :Disconnect ()
80+
81+ -- case 8: disconnect() function
82+ elseif typeof (task .disconnect ) == "function" then
83+ local task = (task :: any ) :: { disconnect : (...unknown ) -> ...unknown }
84+ task :disconnect ()
6885 end
6986 end
7087
Original file line number Diff line number Diff line change @@ -43,6 +43,8 @@ export type Task =
4343 () -> () |
4444 {destroy : (unknown ) -> ()} |
4545 {Destroy : (unknown ) -> ()} |
46+ {disconnect : (unknown ) -> ()} |
47+ {Disconnect : (unknown ) -> ()} |
4648 {Task }
4749
4850-- A scope of tasks to clean up.
Original file line number Diff line number Diff line change @@ -74,6 +74,34 @@ return function()
7474 expect (didRun ).to .equal (true )
7575 end )
7676
77+ it ("should invoke :disconnect() methods" , function ()
78+ local expect = getfenv ().expect
79+
80+ local didRun = false
81+
82+ doCleanup ({
83+ disconnect = function ()
84+ didRun = true
85+ end
86+ })
87+
88+ expect (didRun ).to .equal (true )
89+ end )
90+
91+ it ("should invoke :Disconnect() methods" , function ()
92+ local expect = getfenv ().expect
93+
94+ local didRun = false
95+
96+ doCleanup ({
97+ Disconnect = function ()
98+ didRun = true
99+ end
100+ })
101+
102+ expect (didRun ).to .equal (true )
103+ end )
104+
77105 it ("should clean up contents of arrays" , function ()
78106 local expect = getfenv ().expect
79107
You can’t perform that action at this time.
0 commit comments