Skip to content

Commit 870f45e

Browse files
authored
Merge branch 'main' into fix/exports-jest
2 parents 85ce232 + 7494fb2 commit 870f45e

33 files changed

+1358
-524
lines changed

.github/ISSUE_TEMPLATE/bug-report.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
---
8+
9+
- [ ] Check if updating to the latest version resolves the issue
10+
11+
**Environment**
12+
- [ ] I am using `@preact/signals-core`
13+
- [ ] I am using `@preact/signals`
14+
- [ ] I am using `@preact/signals-react`
15+
- [ ] I understand usage changed in v2, and I've followed the [React Integration instructions](https://github.com/preactjs/signals/tree/main/packages/react#react-integration)
16+
17+
**Describe the bug**
18+
A clear and concise description of what the bug is.
19+
20+
**To Reproduce**
21+
Please provide a link to a StackBlitz/CodeSandbox/Codepen project or a GitHub repository that demonstrates the issue.
22+
23+
Steps to reproduce the behavior:
24+
25+
1. Go to '...'
26+
2. Click on '....'
27+
3. See error
28+
29+
**Expected behavior**
30+
What should have happened when following the steps above?
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: feature request
6+
assignees: ''
7+
---
8+
9+
**Describe the feature you'd love to see**
10+
A clear and concise description of what you'd love to see added to Preact Signals.
11+
12+
**Additional context (optional)**
13+
Add any other context or screenshots about the feature request here.

.github/workflows/compressed-size.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: compressed-size
2+
23
on:
34
pull_request:
45
branches:
@@ -8,13 +9,12 @@ jobs:
89
build:
910
runs-on: ubuntu-latest
1011
steps:
11-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1213

1314
- name: Install pnpm
14-
uses: pnpm/action-setup@v2.2.4
15+
uses: pnpm/action-setup@v3
1516
with:
1617
version: 8
17-
run_install: false
1818

1919
- name: compressed-size-action
2020
uses: preactjs/compressed-size-action@v2

.github/workflows/main.yml

+6-19
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,18 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout
16-
uses: actions/checkout@v3
17-
18-
- name: Install Node.js
19-
uses: actions/setup-node@v3
20-
with:
21-
node-version: 18
16+
uses: actions/checkout@v4
2217

2318
- name: Install pnpm
24-
uses: pnpm/action-setup@v2.2.4
19+
uses: pnpm/action-setup@v3
2520
with:
2621
version: 8
27-
run_install: false
2822

29-
- name: Get pnpm store directory
30-
id: pnpm-cache
31-
run: |
32-
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
33-
34-
- uses: actions/cache@v3
35-
name: Setup pnpm cache
23+
- name: Install Node.js
24+
uses: actions/setup-node@v4
3625
with:
37-
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
38-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
39-
restore-keys: |
40-
${{ runner.os }}-pnpm-store-
26+
node-version: 18
27+
cache: pnpm
4128

4229
- name: Install dependencies
4330
run: pnpm install

.github/workflows/release.yml

+16-20
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,35 @@ on:
88
jobs:
99
release:
1010
name: Release
11+
permissions:
12+
contents: write
13+
id-token: write
14+
issues: read
15+
pull-requests: write
1116
runs-on: ubuntu-latest
1217
steps:
1318
- name: Checkout
14-
uses: actions/checkout@v3
15-
16-
- name: Install Node.js
17-
uses: actions/setup-node@v3
18-
with:
19-
node-version: 18
19+
uses: actions/checkout@v4
2020

2121
- name: Install pnpm
22-
uses: pnpm/action-setup@v2.2.4
22+
uses: pnpm/action-setup@v3
2323
with:
2424
version: 8
25-
run_install: false
2625

27-
- name: Get pnpm store directory
28-
id: pnpm-cache
29-
run: |
30-
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
31-
32-
- uses: actions/cache@v3
33-
name: Setup pnpm cache
26+
- name: Install Node.js
27+
uses: actions/setup-node@v4
3428
with:
35-
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
36-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
37-
restore-keys: |
38-
${{ runner.os }}-pnpm-store-
29+
node-version: 18
30+
cache: pnpm
3931

4032
- name: Install dependencies
4133
run: pnpm install
4234

4335
- name: Create Release Pull Request
44-
uses: changesets/action@master
36+
uses: changesets/action@v1
37+
with:
38+
version: pnpm run version
39+
publish: pnpm changeset publish
4540
env:
4641
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

CONTRIBUTING.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
## Releasing Signals (Maintainers only)
44

5-
This guide is intended for core team members that have the necessary
6-
rights to publish new releases on npm.
5+
This guide is intended for core team members that have the necessary rights to merge pull requests to the `main` branch.
76

8-
1. Merge "Version Packages" PR opened by the changesets-action
9-
2. Switch to the `main` branch and pull the merged PR
10-
3. Run `pnpm release` to publish packages
11-
4. Commit updated `pnpm-lock.yaml` if it changed and push it: `git push -f`
7+
To create a new release, merge "Version Packages" PR opened by the changesets-action. The release workflow will automatically create new releases for the packages that have changesets.

README.md

+36-17
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,6 @@ effect(() => {
7777

7878
Note that you should only use `signal.peek()` if you really need it. Reading a signal's value via `signal.value` is the preferred way in most scenarios.
7979

80-
### `untracked(fn)`
81-
82-
In case when you're receiving a callback that can read some signals, but you don't want to subscribe to them, you can use `untracked` to prevent any subscriptions from happening.
83-
84-
```js
85-
const counter = signal(0);
86-
const effectCount = signal(0);
87-
const fn = () => effectCount.value + 1;
88-
89-
effect(() => {
90-
console.log(counter.value);
91-
92-
// Whenever this effect is triggered, run `fn` that gives new value
93-
effectCount.value = untracked(fn);
94-
});
95-
```
96-
9780
### `computed(fn)`
9881

9982
Data is often derived from other pieces of existing data. The `computed` function lets you combine the values of multiple signals into a new signal that can be reacted to, or even used by additional computeds. When the signals accessed from within a computed callback change, the computed callback is re-executed and its new return value becomes the computed signal's value.
@@ -158,6 +141,25 @@ dispose();
158141
surname.value = "Doe 2";
159142
```
160143

144+
The effect callback may return a cleanup function. The cleanup function gets run once, either when the effect callback is next called _or_ when the effect gets disposed, whichever happens first.
145+
146+
```js
147+
import { signal, effect } from "@preact/signals-core";
148+
149+
const count = signal(0);
150+
151+
const dispose = effect(() => {
152+
const c = count.value;
153+
return () => console.log(`cleanup ${c}`);
154+
});
155+
156+
// Logs: cleanup 0
157+
count.value = 1;
158+
159+
// Logs: cleanup 1
160+
dispose();
161+
```
162+
161163
### `batch(fn)`
162164

163165
The `batch` function allows you to combine multiple signal writes into one single update that is triggered at the end when the callback completes.
@@ -220,6 +222,23 @@ batch(() => {
220222
// Now the callback completed and we'll trigger the effect.
221223
```
222224

225+
### `untracked(fn)`
226+
227+
In case when you're receiving a callback that can read some signals, but you don't want to subscribe to them, you can use `untracked` to prevent any subscriptions from happening.
228+
229+
```js
230+
const counter = signal(0);
231+
const effectCount = signal(0);
232+
const fn = () => effectCount.value + 1;
233+
234+
effect(() => {
235+
console.log(counter.value);
236+
237+
// Whenever this effect is triggered, run `fn` that gives new value
238+
effectCount.value = untracked(fn);
239+
});
240+
```
241+
223242
## License
224243

225244
`MIT`, see the [LICENSE](./LICENSE) file.

0 commit comments

Comments
 (0)