@@ -29,6 +29,28 @@ describe("signal", () => {
29
29
expect ( a + b ) . to . equal ( 3 ) ;
30
30
} ) ;
31
31
32
+ it ( "should notify other listeners of changes after one listener is disposed" , ( ) => {
33
+ const s = signal ( 0 ) ;
34
+ const spy1 = sinon . spy ( ( ) => s . value ) ;
35
+ const spy2 = sinon . spy ( ( ) => s . value ) ;
36
+ const spy3 = sinon . spy ( ( ) => s . value ) ;
37
+
38
+ effect ( spy1 ) ;
39
+ const dispose = effect ( spy2 ) ;
40
+ effect ( spy3 ) ;
41
+
42
+ expect ( spy1 ) . to . be . calledOnce ;
43
+ expect ( spy2 ) . to . be . calledOnce ;
44
+ expect ( spy3 ) . to . be . calledOnce ;
45
+
46
+ dispose ( ) ;
47
+
48
+ s . value = 1 ;
49
+ expect ( spy1 ) . to . be . calledTwice ;
50
+ expect ( spy2 ) . to . be . calledOnce ;
51
+ expect ( spy3 ) . to . be . calledTwice ;
52
+ } ) ;
53
+
32
54
describe ( ".peek()" , ( ) => {
33
55
it ( "should get value" , ( ) => {
34
56
const s = signal ( 1 ) ;
@@ -1000,6 +1022,30 @@ describe("computed()", () => {
1000
1022
expect ( c . value ) . to . equal ( 1 ) ;
1001
1023
} ) ;
1002
1024
1025
+ it ( "should propagate notification to other listeners after one listener is disposed" , ( ) => {
1026
+ const s = signal ( 0 ) ;
1027
+ const c = computed ( ( ) => s . value ) ;
1028
+
1029
+ const spy1 = sinon . spy ( ( ) => c . value ) ;
1030
+ const spy2 = sinon . spy ( ( ) => c . value ) ;
1031
+ const spy3 = sinon . spy ( ( ) => c . value ) ;
1032
+
1033
+ effect ( spy1 ) ;
1034
+ const dispose = effect ( spy2 ) ;
1035
+ effect ( spy3 ) ;
1036
+
1037
+ expect ( spy1 ) . to . be . calledOnce ;
1038
+ expect ( spy2 ) . to . be . calledOnce ;
1039
+ expect ( spy3 ) . to . be . calledOnce ;
1040
+
1041
+ dispose ( ) ;
1042
+
1043
+ s . value = 1 ;
1044
+ expect ( spy1 ) . to . be . calledTwice ;
1045
+ expect ( spy2 ) . to . be . calledOnce ;
1046
+ expect ( spy3 ) . to . be . calledTwice ;
1047
+ } ) ;
1048
+
1003
1049
it ( "should not recompute dependencies out of order" , ( ) => {
1004
1050
const a = signal ( 1 ) ;
1005
1051
const b = signal ( 1 ) ;
0 commit comments