Skip to content

Commit d233896

Browse files
doc: add a signal example
1 parent 867b040 commit d233896

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

packages/signal-polyfill/readme.md

+34-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,37 @@ export function effect(callback) {
6464
```
6565

6666
> [!IMPORTANT]
67-
> The `Signal.subtle` APIs are so named in order to communicate that their correct use requires careful attention to detail. These APIs are not targeted at application-level code, but rather at framework/library authors.
67+
> The `Signal.subtle` APIs are so named in order to communicate that their correct use requires careful attention to detail. These APIs are not targeted at application-level code, but rather at framework/library authors.
68+
69+
### Using signals with decorators
70+
71+
```js
72+
import { Signal } from "signal-polyfill";
73+
74+
export function signal(target) {
75+
const { get } = target;
76+
77+
return {
78+
get() {
79+
return get.call(this).get();
80+
},
81+
82+
set(value) {
83+
get.call(this).set(value);
84+
},
85+
86+
init(value) {
87+
return new Signal.State(value);
88+
},
89+
};
90+
}
91+
92+
export class Person {
93+
@signal accessor firstName = "";
94+
@signal accessor lastName = "";
95+
96+
get fullName() {
97+
return `${this.firstName} ${this.lastName}`;
98+
}
99+
}
100+
```

0 commit comments

Comments
 (0)