File tree 1 file changed +20
-5
lines changed
1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,8 @@ export function effect(callback) {
87
87
88
88
### Combining signals and decorators
89
89
90
+ A class accessor decorator can be combined with the ` Signal.State() ` API to enable improved DX.
91
+
90
92
``` js
91
93
import { Signal } from " signal-polyfill" ;
92
94
@@ -107,13 +109,26 @@ export function signal(target) {
107
109
},
108
110
};
109
111
}
112
+ ```
113
+
114
+ The above decorator can be used on public or ** private** accessors, enabling reactivity while carefully controlling state mutations.
115
+
116
+ ``` js
117
+ export class Counter {
118
+ @signal accessor #value = 0 ;
119
+
120
+ get value () {
121
+ return this .#value;
122
+ }
110
123
111
- export class Person {
112
- @signal accessor firstName = " " ;
113
- @signal accessor lastName = " " ;
124
+ increment () {
125
+ this .#value ++ ;
126
+ }
114
127
115
- get fullName () {
116
- return ` ${ this .firstName } ${ this .lastName } ` ;
128
+ decrement () {
129
+ if (this .#value > 0 ) {
130
+ this .#value-- ;
131
+ }
117
132
}
118
133
}
119
134
```
You can’t perform that action at this time.
0 commit comments