@quenty/signal 2.0.0 → 2.0.1
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 +8 -0
- package/LICENSE.md +1 -1
- package/README.md +5 -3
- package/package.json +2 -2
- package/src/Shared/Signal.lua +52 -20
- package/src/Shared/SignalUtils.lua +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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
|
+
## [2.0.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/signal@2.0.0...@quenty/signal@2.0.1) (2021-12-30)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/signal
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [2.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/signal@1.2.0...@quenty/signal@2.0.0) (2021-09-05)
|
|
7
15
|
|
|
8
16
|
|
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
## Signal
|
|
2
2
|
<div align="center">
|
|
3
|
-
<a href="http://quenty.github.io/
|
|
4
|
-
<img src="https://
|
|
3
|
+
<a href="http://quenty.github.io/NevermoreEngine/">
|
|
4
|
+
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
|
|
5
5
|
</a>
|
|
6
6
|
<a href="https://discord.gg/mhtGUS8">
|
|
7
|
-
<img src="https://img.shields.io/
|
|
7
|
+
<img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
|
|
8
8
|
</a>
|
|
9
9
|
<a href="https://github.com/Quenty/NevermoreEngine/actions">
|
|
10
10
|
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
</div>
|
|
13
13
|
A simple signal implementation for Roblox
|
|
14
14
|
|
|
15
|
+
<div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/Signal">View docs →</a></div>
|
|
16
|
+
|
|
15
17
|
## Installation
|
|
16
18
|
```
|
|
17
19
|
npm install @quenty/signal --save
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/signal",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A simple signal implementation for Roblox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "d146c77d0a8e452824de0ab0b4b03ba0370bcc1b"
|
|
33
33
|
}
|
package/src/Shared/Signal.lua
CHANGED
|
@@ -1,9 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
--[=[
|
|
2
|
+
Lua-side duplication of the API of events on Roblox objects.
|
|
3
|
+
Signals are needed for to ensure that for local events objects are passed by
|
|
4
|
+
reference rather than by value where possible, as the BindableEvent objects
|
|
5
|
+
always pass signal arguments by value, meaning tables will be deep copied.
|
|
6
|
+
Roblox's deep copy method parses to a non-lua table compatable format.
|
|
7
|
+
|
|
8
|
+
This class is designed to work both in deferred mode and in regular mode.
|
|
9
|
+
It follows whatever mode is set.
|
|
10
|
+
|
|
11
|
+
```lua
|
|
12
|
+
local signal = Signal.new()
|
|
13
|
+
|
|
14
|
+
local arg = {}
|
|
15
|
+
|
|
16
|
+
signal:Connect(function(value)
|
|
17
|
+
assert(arg == value, "Tables are preserved when firing a Signal")
|
|
18
|
+
end)
|
|
19
|
+
|
|
20
|
+
signal:Fire(arg)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
:::info
|
|
24
|
+
Why this over a direct [BindableEvent]? Well, in this case, the signal
|
|
25
|
+
prevents Roblox from trying to serialize and desialize each table reference
|
|
26
|
+
fired through the BindableEvent.
|
|
27
|
+
:::
|
|
28
|
+
|
|
29
|
+
@class Signal
|
|
30
|
+
]=]
|
|
7
31
|
|
|
8
32
|
local HttpService = game:GetService("HttpService")
|
|
9
33
|
|
|
@@ -13,9 +37,10 @@ local Signal = {}
|
|
|
13
37
|
Signal.__index = Signal
|
|
14
38
|
Signal.ClassName = "Signal"
|
|
15
39
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
40
|
+
--[=[
|
|
41
|
+
Constructs a new signal.
|
|
42
|
+
@return Signal<T>
|
|
43
|
+
]=]
|
|
19
44
|
function Signal.new()
|
|
20
45
|
local self = setmetatable({}, Signal)
|
|
21
46
|
|
|
@@ -40,10 +65,10 @@ function Signal.new()
|
|
|
40
65
|
return self
|
|
41
66
|
end
|
|
42
67
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
68
|
+
--[=[
|
|
69
|
+
Fire the event with the given arguments. All handlers will be invoked. Handlers follow
|
|
70
|
+
@param ... T -- Variable arguments to pass to handler
|
|
71
|
+
]=]
|
|
47
72
|
function Signal:Fire(...)
|
|
48
73
|
if not self._bindableEvent then
|
|
49
74
|
warn(("Signal is already destroyed. %s"):format(self._source))
|
|
@@ -60,9 +85,11 @@ function Signal:Fire(...)
|
|
|
60
85
|
self._bindableEvent:Fire(key)
|
|
61
86
|
end
|
|
62
87
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
--
|
|
88
|
+
--[=[
|
|
89
|
+
Connect a new handler to the event. Returns a connection object that can be disconnected.
|
|
90
|
+
@param handler (... T) -> () -- Function handler called when `:Fire(...)` is called
|
|
91
|
+
@return RBXScriptConnection
|
|
92
|
+
]=]
|
|
66
93
|
function Signal:Connect(handler)
|
|
67
94
|
if not (type(handler) == "function") then
|
|
68
95
|
error(("connect(%s)"):format(typeof(handler)), 2)
|
|
@@ -81,8 +108,11 @@ function Signal:Connect(handler)
|
|
|
81
108
|
end)
|
|
82
109
|
end
|
|
83
110
|
|
|
84
|
-
|
|
85
|
-
|
|
111
|
+
--[=[
|
|
112
|
+
Wait for fire to be called, and return the arguments it was given.
|
|
113
|
+
@yields
|
|
114
|
+
@return T
|
|
115
|
+
]=]
|
|
86
116
|
function Signal:Wait()
|
|
87
117
|
local key = self._bindableEvent.Event:Wait()
|
|
88
118
|
local args = self._argMap[key]
|
|
@@ -94,8 +124,10 @@ function Signal:Wait()
|
|
|
94
124
|
end
|
|
95
125
|
end
|
|
96
126
|
|
|
97
|
-
|
|
98
|
-
|
|
127
|
+
--[=[
|
|
128
|
+
Disconnects all connected events to the signal. Voids the signal as unusable.
|
|
129
|
+
Sets the metatable to nil.
|
|
130
|
+
]=]
|
|
99
131
|
function Signal:Destroy()
|
|
100
132
|
if self._bindableEvent then
|
|
101
133
|
-- This should disconnect all events, but in-flight events should still be
|