Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Elttob/Fusion
Browse files Browse the repository at this point in the history
  • Loading branch information
dphfox committed Jan 31, 2023
2 parents cd0622a + bcf84d0 commit 398b20c
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 11 deletions.
12 changes: 6 additions & 6 deletions docs/api-reference/animation/spring.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ captured.
Instantaneously moves the spring to a new position. This does not affect the
velocity of the spring.

If the given value doesn't have the same type as the spring's current value, an
error will be thrown.
If the given value doesn't have the same type as the spring's current value,
the position will snap instantly to the new value.

```Lua
(newPosition: T) -> ()
Expand All @@ -93,8 +93,8 @@ error will be thrown.
Overwrites the velocity of this spring. This does not have an immediate effect
on the position of the spring.

If the given value doesn't have the same type as the spring's current value, an
error will be thrown.
If the given value doesn't have the same type as the spring's current value,
the velocity will snap instantly to the new value.

```Lua
(newVelocity: T) -> ()
Expand All @@ -115,8 +115,8 @@ error will be thrown.
Adds to the velocity of this spring. This does not have an immediate effect
on the position of the spring.

If the given value doesn't have the same type as the spring's current value, an
error will be thrown.
If the given value doesn't have the same type as the spring's current value,
the velocity will snap instantly to the new value.

```Lua
(deltaVelocity: T) -> ()
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/instances/child.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ to parent multiple instances at once and state objects can be used to make the
children dynamic.

```Lua
Instance | {Child} | StateObject<Child>
Instance | {[any]: Child} | StateObject<Child>
```

-----
Expand Down
50 changes: 50 additions & 0 deletions docs/api-reference/instances/cleanup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<nav class="fusiondoc-api-breadcrumbs">
<a href="../..">Fusion</a>
<a href="..">Instances</a>
</nav>

<h1 class="fusiondoc-api-header" markdown>
<span class="fusiondoc-api-icon" markdown>:octicons-key-24:</span>
<span class="fusiondoc-api-name">Cleanup</span>
<span class="fusiondoc-api-pills">
<span class="fusiondoc-api-pill-type">special key</span>
<span class="fusiondoc-api-pill-since">since v0.2</span>
</span>
</h1>

Cleans up all items given to it when the instance is destroyed, equivalent to
passing the items to `Fusion.cleanup`.

-----

## Example Usage

```Lua
local example1 = New "Folder" {
[Cleanup] = function()
print("I'm in danger!")
end
}

local example2 = New "Folder" {
[Cleanup] = example1
}

local example3 = New "Folder" {
[Cleanup] = {
RunService.RenderStepped:Connect(print),
function()
print("I'm in danger also!")
end,
example2
}
}

example3:Destroy()
```

-----

## Technical Details

This special key runs at the `observer` stage.
4 changes: 2 additions & 2 deletions docs/api-reference/instances/specialkey.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ instance processing. Compatible with the [New](./new.md) and
apply: (
self: SpecialKey,
value: any,
applyTo: SemiWeakRef,
applyTo: Instance,
cleanupTasks: {Task}
) -> ()
}
Expand Down Expand Up @@ -52,7 +52,7 @@ Example.kind = "Example"
Example.stage = "observer"

function Example:apply(value, applyTo, cleanupTasks)
local conn = applyTo.instance:GetAttributeChangedSignal("Foo"):Connect(function()
local conn = applyTo:GetAttributeChangedSignal("Foo"):Connect(function()
print("My value is", value)
end)
table.insert(cleanupTasks, conn)
Expand Down
53 changes: 53 additions & 0 deletions docs/api-reference/state/cleanup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<nav class="fusiondoc-api-breadcrumbs">
<a href="../..">Fusion</a>
<a href="..">State</a>
</nav>

<h1 class="fusiondoc-api-header" markdown>
<span class="fusiondoc-api-icon" markdown>:octicons-code-24:</span>
<span class="fusiondoc-api-name">cleanup</span>
<span class="fusiondoc-api-pills">
<span class="fusiondoc-api-pill-type">function</span>
<span class="fusiondoc-api-pill-since">since v0.2</span>
</span>
</h1>

Attempts to destroy all destructible objects passed to it.

```Lua
(...any) -> ()
```

-----

## Parameters

- `...` - Any objects that need to be destroyed.

-----

## Example Usage

```Lua
Fusion.cleanup(
workspace.Part1,
RunService.RenderStepped:Connect(print),
function()
print("I will be run!")
end
)
```

-----

## Destruction Behaviour

Destruction behaviour varies by type:

- if `Instance`, `:Destroy()` is called
- ...else if `RBXScriptConnection`, `:Disconnect()` is called
- ...else if `function`, it is called
- ...else if `{destroy: (self) -> ()}`, `:destroy()` is called
- ...else if `{Destroy: (self) -> ()}`, `:Destroy()` is called
- ...else if `{any}`, `Fusion.cleanup` is called on all members
- ...else nothing occurs.
4 changes: 2 additions & 2 deletions docs/api-reference/state/computed.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Calculates a single value based on the returned values from other state objects.

## Parameters

- `processor: () -> (T, any?)` - computes and returns values to be returned from
- `processor: () -> (T, M)` - computes and returns values to be returned from
the computed object, optionally returning extra values for the destructor alone

- `destructor: ((T, any?) -> ())?` - disposes of values generated by `processor`
- `destructor: ((T, M) -> ())?` - disposes of values generated by `processor`
when they are no longer in use

-----
Expand Down
36 changes: 36 additions & 0 deletions docs/api-reference/state/doNothing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<nav class="fusiondoc-api-breadcrumbs">
<a href="../..">Fusion</a>
<a href="..">State</a>
</nav>

<h1 class="fusiondoc-api-header" markdown>
<span class="fusiondoc-api-icon" markdown>:octicons-code-24:</span>
<span class="fusiondoc-api-name">doNothing</span>
<span class="fusiondoc-api-pills">
<span class="fusiondoc-api-pill-type">function</span>
<span class="fusiondoc-api-pill-since">since v0.2</span>
</span>
</h1>

No-op function - does nothing at all, and returns nothing at all. Intended for
use as a destructor when no destruction is needed.

```Lua
(...any) -> ()
```

-----

## Parameters

- `...` - Any objects.

-----

## Example Usage

```Lua
local foo = Computed(function()
return workspace.Part
end, Fusion.doNothing)
```
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ nav:
- api-reference/state/index.md
- CanBeState: api-reference/state/canbestate.md
- Computed: api-reference/state/computed.md
- cleanup: api-reference/state/cleanup.md
- Dependency: api-reference/state/dependency.md
- Dependent: api-reference/state/dependent.md
- doNothing: api-reference/state/doNothing.md
- ForKeys: api-reference/state/forkeys.md
- ForPairs: api-reference/state/forpairs.md
- ForValues: api-reference/state/forvalues.md
Expand Down

0 comments on commit 398b20c

Please sign in to comment.