-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
227 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<nav class="fusiondoc-api-breadcrumbs"> | ||
<span>Memory</span> | ||
<span>Members</span> | ||
<span>insert</span> | ||
</nav> | ||
|
||
<h1 class="fusiondoc-api-header" markdown> | ||
<span class="fusiondoc-api-icon" markdown>:octicons-workflow-24:</span> | ||
<span class="fusiondoc-api-name">insert</span> | ||
<span class="fusiondoc-api-type"> | ||
-> Tasks... | ||
</span> | ||
</h1> | ||
|
||
```Lua | ||
function Fusion.insert<Tasks...>( | ||
scope: Scope<unknown>, | ||
...: Tasks... | ||
): Tasks... | ||
``` | ||
|
||
Inserts destruction [tasks](../../types/task) passed in to the | ||
[scope](../../types/scope). Returns the clean up tasks to be used for variable | ||
declarations. | ||
|
||
|
||
!!! success "Use scoped() method syntax" | ||
This function is intended to be accessed as a method on a scope: | ||
```Lua | ||
local conn, ins = scope:insert( | ||
RunService.Heartbeat:Connnect(doUpdate), | ||
Instance.new("Part", workspace) | ||
) | ||
``` | ||
|
||
----- | ||
|
||
## Parameters | ||
|
||
<h3 markdown> | ||
scope | ||
<span class="fusiondoc-api-type"> | ||
: <a href="../../types/scope">Scope</a><unknown> | ||
</span> | ||
</h3> | ||
|
||
The [scope](../../types/scope) which should be used to store | ||
destruction tasks. | ||
|
||
<h3 markdown> | ||
... | ||
<span class="fusiondoc-api-type"> | ||
: Tasks... | ||
</span> | ||
</h3> | ||
|
||
The destruction [tasks](../../types/task) which should be inserted into the | ||
scope. | ||
|
||
----- | ||
|
||
<h2 markdown> | ||
Returns | ||
<span class="fusiondoc-api-type"> | ||
-> Tasks... | ||
</span> | ||
</h2> | ||
|
||
The destruction [tasks](../../types/task) that has been inserted into the scope. | ||
|
||
----- | ||
|
||
## Learn More | ||
|
||
- [Scopes tutorial](../../../../tutorials/fundamentals/scopes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
{ | ||
"name": "@dphfox/fusion", | ||
"version": "0.3.0", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/dphfox/Fusion.git" | ||
}, | ||
"contributors": [ | ||
"dphfox" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/dphfox/Fusion/issues" | ||
} | ||
{ | ||
"name": "@dphfox/fusion", | ||
"version": "0.3.0", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/dphfox/Fusion.git" | ||
}, | ||
"contributors": [ | ||
"dphfox" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/dphfox/Fusion/issues" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--!strict | ||
--!nolint LocalUnused | ||
--!nolint LocalShadow | ||
local task = nil -- Disable usage of Roblox's task scheduler | ||
|
||
--[[ | ||
Inserts clean up tasks passed in to the scope. | ||
]] | ||
local Package = script.Parent.Parent | ||
local Types = require(Package.Types) | ||
|
||
local function insert<Tasks...>( | ||
scope: Types.Scope<unknown>, | ||
...: Tasks... | ||
): Tasks... | ||
for index = 1, select("#", ...) do | ||
table.insert(scope, select(index, ...)) | ||
end | ||
return ... | ||
end | ||
|
||
return insert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
--!strict | ||
--!nolint LocalUnused | ||
local task = nil -- Disable usage of Roblox's task scheduler | ||
|
||
local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||
local Fusion = ReplicatedStorage.Fusion | ||
|
||
local doCleanup = require(Fusion.Memory.doCleanup) | ||
local insert = require(Fusion.Memory.insert) | ||
|
||
return function() | ||
local it = getfenv().it | ||
|
||
it("should accept zero tasks", function() | ||
local expect = getfenv().expect | ||
|
||
local scope = scoped() | ||
insert(scope) | ||
|
||
expect(#scope).to.equal(0) | ||
end) | ||
|
||
it("should accept single tasks", function() | ||
local expect = getfenv().expect | ||
|
||
local isDestroyed = false | ||
local scope = scoped() | ||
insert(scope, function() | ||
isDestroyed = true | ||
end) | ||
|
||
expect(#scope).to.equal(1) | ||
doCleanup(scope) | ||
|
||
expect(isDestroyed).to.equal(true) | ||
end) | ||
|
||
it("should accept multiple tasks", function() | ||
local expect = getfenv().expect | ||
|
||
local counter = 0 | ||
local scope = scoped() | ||
|
||
insert(scope, function() | ||
counter += 1 | ||
end) | ||
insert(scope, function() | ||
counter += 1 | ||
end) | ||
insert(scope, { | ||
function() | ||
counter += 1 | ||
end | ||
}) | ||
|
||
expect(#scope).to.equal(3) | ||
doCleanup(scope) | ||
expect(counter).to.equal(3) | ||
end) | ||
|
||
it("should return the given tasks", function() | ||
local expect = getfenv().expect | ||
|
||
local counter = 0 | ||
local function onDestroy() | ||
counter += 1 | ||
end | ||
local function onDestroy2() | ||
counter += 2 | ||
end | ||
local scope = scoped() | ||
|
||
local returnedDestroy, returnedDestroy2 = insert(scope, onDestroy, onDestroy2) | ||
expect(returnedDestroy).to.equal(onDestroy) | ||
expect(returnedDestroy2).to.equal(onDestroy2) | ||
expect(#scope).to.equal(2) | ||
doCleanup(scope) | ||
expect(counter).to.equal(3) | ||
end) | ||
end |