You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
-3Lines changed: 0 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,9 +6,6 @@ _(none)_
6
6
---
7
7
8
8
## 2.0.0 (2023-03-29)
9
-
_(none)_
10
-
11
-
## 2.0.0-2 (2023-03-29)
12
9
13
10
-`.add` is now type safe. The type of the listener is checked against the type variable in the constructor as well as an optional "flavor".
14
11
-`.add` now returns a node reference instead of a object. The returned node cannot be removed directly; it must be from the signal using `MiniSignal#detach`.
Copy file name to clipboardExpand all lines: README.md
+23-7Lines changed: 23 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,15 +18,16 @@ MiniSignals v2.0.0 has been rewritten in TypeScript and had it's API changed to
18
18
19
19
New features:
20
20
21
-
-`.add` now returns a weak node reference which can be used to remove the listener directly from the signal. Reduces memory leaks.
21
+
-`.add` now returns a node reference which can be used to remove the listener directly from the signal. Reduces memory leaks.
22
22
-`.add` is now type safe. The type of the listener is checked against the type variable in the constructor as well as an optional "flavor".
23
23
24
24
Breaking changes:
25
25
26
-
-`.add` now returns a node reference instead of a object. The returned node cannot be removed directly; it must be from the signal using `MiniSignal#detach`.
26
+
-`.add` now returns a node reference instead of an object. The returned node cannot be removed directly; it must be from the signal using `MiniSignal#detach`.
27
27
-`.once` has been removed. Use `.add` instead with a call to `.detach` in the callback.
28
28
- The `thisArg` parameter has been removed from `.add`. Use `.add` with a call to `.bind` or (preferred) use an arrow function with a closure.
29
29
-`.dispatch` now throws an error if the signal is already dispatching.
30
+
`.detach` now throws an error if the node reference was not generated from the signal.
30
31
31
32
## Install
32
33
@@ -36,12 +37,12 @@ Breaking changes:
36
37
npm install mini-signals
37
38
```
38
39
39
-
## Example Usage
40
+
## Examples
40
41
41
42
```ts
42
43
import { MiniSignal } from'mini-signals';
43
44
44
-
const mySignal =newMiniSignal<[string, string]>(); // the type variable is optional and defines the parameters to be dispatched
45
+
const mySignal =newMiniSignal<[string, string]>(); // the type variable optionally and defines the parameters to be dispatched
45
46
46
47
const binding =mySignal.add((foo:string, bar:string) => { // add listener, note the parameter types match the type variable in the constructor
47
48
console.log('signal dispatched');
@@ -50,10 +51,10 @@ const binding = mySignal.add((foo: string, bar: string) => { // add listener, no
50
51
});
51
52
52
53
mySignal.dispatch('foo', 'bar'); // dispatch signal passing custom parameters
53
-
binding.detach(); // remove a single listener
54
+
mySignal.detach(binding); // remove a single listener
myOtherSignal.detach(binding); // TypeScript error: Argument of type 'MiniSignalBinding<[string, string], "mySignal">' is not assignable to parameter of type 'MiniSignalBinding<[string, string], "myOtherSignal">'.
87
+
```
88
+
73
89
## API
74
90
75
-
See [API.md](https://github.com/Hypercubed/mini-signals/blob/master/API.md)
91
+
See [API.md](https://github.com/Hypercubed/mini-signals/blob/master/docs/classes/MiniSignal.md)
Copy file name to clipboardExpand all lines: docs/README.md
+30-15Lines changed: 30 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,23 +12,24 @@ Custom event/messaging system for TypeScript/JavaScript inspired by [js-signals]
12
12
13
13
There are several advantages to signals over event-emitters (see [Comparison between different Observer Pattern implementations](https://github.com/millermedeiros/js-signals/wiki/Comparison-between-different-Observer-Pattern-implementations)). However, the current implementation of [js-signals](https://github.com/millermedeiros/js-signals) is (arguably) slow compared to other implementations (see [EventsSpeedTests](https://github.com/Hypercubed/EventsSpeedTests)). `mini-signals` is a fast, minimal emitter, with an API similar to [js-signals](https://github.com/millermedeiros/js-signals).
14
14
15
-
> Note: Signals here are the type defined by [js-signals](https://github.com/millermedeiros/js-signals) inspired by AS3-Signals. They should not to be confused with [SolidJS](https://www.solidjs.com/tutorial/introduction_signals) or Angular signals.
15
+
> Note: Signals here are the type defined by Miller Medeiros in [js-signals](https://github.com/millermedeiros/js-signals) inspired by AS3-Signals. They should not to be confused with [SolidJS](https://www.solidjs.com/tutorial/introduction_signals) or [Angular signals](https://github.com/angular/angular/discussions/49090).
16
16
17
17
## mini-signals 2.0.0
18
18
19
19
MiniSignals v2.0.0 has been rewritten in TypeScript and had it's API changed to improve performance and add type safety.
20
20
21
21
New features:
22
22
23
-
-`.add` now returns a weak node reference which can be used to remove the listener directly from the signal. Reduces memory leaks.
24
-
-`.add` is now type safe. The type of the listener is checked against the type variable in the constructor.
23
+
-`.add` now returns a node reference which can be used to remove the listener directly from the signal. Reduces memory leaks.
24
+
-`.add` is now type safe. The type of the listener is checked against the type variable in the constructor as well as an optional "flavor".
25
25
26
26
Breaking changes:
27
27
28
-
-`.add` now returns a node reference instead of a object, which had a `detach` method. The node reference can be used to remove the listener directly from the signal.
29
-
-`.once` has been removed. Use `.add` instead with a call to `.detach` in the listener.
30
-
- The `thisArg` parameter has been removed from `.add`. Use `.add` with a call to `.bind` or use an arrow function with a closure.
28
+
-`.add` now returns a node reference instead of an object. The returned node cannot be removed directly; it must be from the signal using `MiniSignal#detach`.
29
+
-`.once` has been removed. Use `.add` instead with a call to `.detach` in the callback.
30
+
- The `thisArg` parameter has been removed from `.add`. Use `.add` with a call to `.bind` or (preferred) use an arrow function with a closure.
31
31
-`.dispatch` now throws an error if the signal is already dispatching.
32
+
`.detach` now throws an error if the node reference was not generated from the signal.
32
33
33
34
## Install
34
35
@@ -38,12 +39,12 @@ Breaking changes:
38
39
npm install mini-signals
39
40
```
40
41
41
-
## Example Usage
42
+
## Examples
42
43
43
44
```ts
44
45
import { MiniSignal } from'mini-signals';
45
46
46
-
const mySignal =newMiniSignal<[string, string]>(); // the type variable is optional and defines the parameters to be dispatched
47
+
const mySignal =newMiniSignal<[string, string]>(); // the type variable optionally and defines the parameters to be dispatched
47
48
48
49
const binding =mySignal.add((foo:string, bar:string) => { // add listener, note the parameter types match the type variable in the constructor
49
50
console.log('signal dispatched');
@@ -52,30 +53,44 @@ const binding = mySignal.add((foo: string, bar: string) => { // add listener, no
52
53
});
53
54
54
55
mySignal.dispatch('foo', 'bar'); // dispatch signal passing custom parameters
55
-
binding.detach(); // remove a single listener
56
+
mySignal.detach(binding); // remove a single listener
56
57
```
57
58
58
-
## Another Example
59
+
###Another Example
59
60
60
61
```ts
61
62
const myObject = {
62
63
foo: "bar",
63
-
updated: newMiniSignal<never, typeofmyObject>() // in this case the type variable is never, since we are not passing any parameters
64
+
updated: newMiniSignal<never>() // in this case the type variable is never, since we are not passing any parameters
myOtherSignal.detach(binding); // TypeScript error: Argument of type 'MiniSignalBinding<[string, string], "mySignal">' is not assignable to parameter of type 'MiniSignalBinding<[string, string], "myOtherSignal">'.
89
+
```
90
+
76
91
## API
77
92
78
-
See [API.md](https://github.com/Hypercubed/mini-signals/blob/master/API.md)
93
+
See [API.md](https://github.com/Hypercubed/mini-signals/blob/master/docs/classes/MiniSignal.md)
0 commit comments