@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 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
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014 Quenty
3
+ Copyright (c) 2014-2021 Quenty
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  ## Signal
2
2
  <div align="center">
3
- <a href="http://quenty.github.io/api/">
4
- <img src="https://img.shields.io/badge/docs-website-green.svg" alt="Documentation" />
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/badge/discord-nevermore-blue.svg" alt="Discord" />
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.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": "c06170ec47b0d4520c587ce2e6404d14b5dbb851"
32
+ "gitHead": "d146c77d0a8e452824de0ab0b4b03ba0370bcc1b"
33
33
  }
@@ -1,9 +1,33 @@
1
- --- Lua-side duplication of the API of events on Roblox objects.
2
- -- Signals are needed for to ensure that for local events objects are passed by
3
- -- reference rather than by value where possible, as the BindableEvent objects
4
- -- always pass signal arguments by value, meaning tables will be deep copied.
5
- -- Roblox's deep copy method parses to a non-lua table compatable format.
6
- -- @classmod Signal
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
- --- Constructs a new signal.
17
- -- @constructor Signal.new()
18
- -- @treturn Signal
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
- --- Fire the event with the given arguments. All handlers will be invoked. Handlers follow
44
- -- Roblox signal conventions.
45
- -- @param ... Variable arguments to pass to handler
46
- -- @treturn nil
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
- --- Connect a new handler to the event. Returns a connection object that can be disconnected.
64
- -- @tparam function handler Function handler called with arguments passed when `:Fire(...)` is called
65
- -- @treturn Connection Connection object that can be disconnected
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
- --- Wait for fire to be called, and return the arguments it was given.
85
- -- @treturn ... Variable arguments from connection
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
- --- Disconnects all connected events to the signal. Voids the signal as unusable.
98
- -- @treturn nil
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
@@ -1,5 +1,7 @@
1
- --- Utilities involving signals
2
- -- @module SignalUtils
1
+ --[=[
2
+ Utilities involving signals
3
+ @class SignalUtils
4
+ ]=]
3
5
 
4
6
  local SignalUtils = {}
5
7