Skip to content

Commit

Permalink
Merge branch 'main' into demo/bench
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored Jul 14, 2024
2 parents 96a2e6f + 26d49bf commit 938ceaa
Show file tree
Hide file tree
Showing 31 changed files with 967 additions and 493 deletions.
30 changes: 30 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---

- [ ] Check if updating to the latest version resolves the issue

**Environment**
- [ ] I am using `@preact/signals-core`
- [ ] I am using `@preact/signals`
- [ ] I am using `@preact/signals-react`
- [ ] 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)

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Please provide a link to a StackBlitz/CodeSandbox/Codepen project or a GitHub repository that demonstrates the issue.

Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. See error

**Expected behavior**
What should have happened when following the steps above?
13 changes: 13 additions & 0 deletions .github/ISSUE_TEMPLATE/feature-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: feature request
assignees: ''
---

**Describe the feature you'd love to see**
A clear and concise description of what you'd love to see added to Preact Signals.

**Additional context (optional)**
Add any other context or screenshots about the feature request here.
6 changes: 3 additions & 3 deletions .github/workflows/compressed-size.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: compressed-size

on:
pull_request:
branches:
Expand All @@ -8,13 +9,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v3
with:
version: 8
run_install: false

- name: compressed-size-action
uses: preactjs/compressed-size-action@v2
Expand Down
25 changes: 6 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18
uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v3
with:
version: 8
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
- name: Install Node.js
uses: actions/setup-node@v4
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
node-version: 18
cache: pnpm

- name: Install dependencies
run: pnpm install
Expand Down
36 changes: 16 additions & 20 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,35 @@ on:
jobs:
release:
name: Release
permissions:
contents: write
id-token: write
issues: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18
uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v3
with:
version: 8
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
- name: Install Node.js
uses: actions/setup-node@v4
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
node-version: 18
cache: pnpm

- name: Install dependencies
run: pnpm install

- name: Create Release Pull Request
uses: changesets/action@master
uses: changesets/action@v1
with:
version: pnpm run version
publish: pnpm changeset publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
8 changes: 2 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

## Releasing Signals (Maintainers only)

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

1. Merge "Version Packages" PR opened by the changesets-action
2. Switch to the `main` branch and pull the merged PR
3. Run `pnpm release` to publish packages
4. Commit updated `pnpm-lock.yaml` if it changed and push it: `git push -f`
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.
53 changes: 36 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,6 @@ effect(() => {

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.

### `untracked(fn)`

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.

```js
const counter = signal(0);
const effectCount = signal(0);
const fn = () => effectCount.value + 1;

effect(() => {
console.log(counter.value);

// Whenever this effect is triggered, run `fn` that gives new value
effectCount.value = untracked(fn);
});
```

### `computed(fn)`

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.
Expand Down Expand Up @@ -158,6 +141,25 @@ dispose();
surname.value = "Doe 2";
```

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.

```js
import { signal, effect } from "@preact/signals-core";

const count = signal(0);

const dispose = effect(() => {
const c = count.value;
return () => console.log(`cleanup ${c}`);
});

// Logs: cleanup 0
count.value = 1;

// Logs: cleanup 1
dispose();
```

### `batch(fn)`

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

### `untracked(fn)`

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.

```js
const counter = signal(0);
const effectCount = signal(0);
const fn = () => effectCount.value + 1;

effect(() => {
console.log(counter.value);

// Whenever this effect is triggered, run `fn` that gives new value
effectCount.value = untracked(fn);
});
```

## License

`MIT`, see the [LICENSE](./LICENSE) file.
8 changes: 2 additions & 6 deletions mangle.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
},
"minify": {
"mangle": {
"reserved": [
"useSignal",
"useComputed",
"useSignalEffect"
],
"reserved": ["useSignal", "useComputed", "useSignalEffect"],
"keep_classnames": true,
"properties": {
"regex": "^_[^_]",
Expand Down Expand Up @@ -45,7 +41,7 @@
"$_node": "n",
"$_targets": "t",
"core: Computed": "",
"$_compute": "x",
"$_fn": "x",
"$_globalVersion": "g",
"core: Effect": "",
"$_callback": "c",
Expand Down
26 changes: 12 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "preact-signals",
"private": true,
"scripts": {
"prebuild": "rimraf packages/core/dist/ packages/preact/dist",
"prebuild": "shx rm -rf packages/*/dist/",
"build": "pnpm build:core && pnpm build:preact && pnpm build:react-runtime && pnpm build:react-auto && pnpm build:react && pnpm build:react-transform",
"_build": "microbundle --raw --globals @preact/signals-core=preactSignalsCore,preact/hooks=preactHooks,@preact/signals-react/runtime=reactSignalsRuntime",
"build:core": "pnpm _build --cwd packages/core && pnpm postbuild:core",
Expand All @@ -11,12 +11,11 @@
"build:react-auto": "pnpm _build --cwd packages/react/auto && pnpm postbuild:react-auto",
"build:react-runtime": "pnpm _build --cwd packages/react/runtime && pnpm postbuild:react-runtime",
"build:react-transform": "pnpm _build --no-compress --cwd packages/react-transform",
"postbuild:core": "cd packages/core/dist && mv -f index.d.ts signals-core.d.ts",
"postbuild:preact": "cd packages/preact/dist && mv -f preact/src/index.d.ts signals.d.ts && rm -dr preact",
"postbuild:react": "cd packages/react/dist && mv -f react/src/index.d.ts signals.d.ts && rm -dr react",
"postbuild:react-auto": "cd packages/react/auto/dist && mv -f react/auto/src/*.d.ts . && rm -dr react",
"postbuild:react-runtime": "cd packages/react/runtime/dist && mv -f react/runtime/src/*.d.ts . && rm -dr react",
"postbuild": "node ./scripts/node-13-exports.js",
"postbuild:core": "cd packages/core/dist && shx mv -f index.d.ts signals-core.d.ts",
"postbuild:preact": "cd packages/preact/dist && shx mv -f preact/src/index.d.ts signals.d.ts && shx rm -rf preact",
"postbuild:react": "cd packages/react/dist && shx mv -f react/src/index.d.ts signals.d.ts && shx rm -rf react",
"postbuild:react-auto": "cd packages/react/auto/dist && shx mv -f react/auto/src/*.d.ts . && shx rm -rf react",
"postbuild:react-runtime": "cd packages/react/runtime/dist && shx mv -f react/runtime/src/*.d.ts . && shx rm -rf react",
"lint": "pnpm lint:eslint && pnpm lint:tsc",
"lint:eslint": "eslint 'packages/**/*.{ts,tsx,js,jsx}'",
"lint:tsc": "tsc -p tsconfig.json --noEmit",
Expand All @@ -36,9 +35,9 @@
"docs:preview": "cd docs && pnpm preview",
"ci:build": "pnpm build && pnpm docs:build",
"ci:test": "pnpm lint && pnpm test",
"release": "pnpm changeset version && pnpm install && git add -A && git commit -m 'Version Packages' && changeset tag && pnpm publish -r",
"prepare": "husky install",
"format": "prettier --ignore-path .gitignore --write '**/*.{js,jsx,ts,tsx,yml,json,md}'"
"format": "prettier --ignore-path .gitignore --write '**/*.{js,jsx,ts,tsx,yml,json,md}'",
"version": "pnpm changeset version && pnpm i --lockfile-only"
},
"authors": [
"The Preact Authors (https://github.com/preactjs/signals/contributors)"
Expand All @@ -56,8 +55,8 @@
"@babel/preset-typescript": "^7.23.3",
"@babel/register": "^7.22.15",
"@babel/standalone": "^7.23.4",
"@changesets/changelog-github": "^0.4.6",
"@changesets/cli": "^2.24.2",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@types/babel__traverse": "^7.18.5",
"@types/chai": "^4.3.3",
"@types/mocha": "^9.1.1",
Expand Down Expand Up @@ -89,7 +88,7 @@
"microbundle": "^0.15.1",
"mocha": "^10.0.0",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"shx": "^0.3.4",
"sinon": "^14.0.0",
"sinon-chai": "^3.7.0",
"typescript": "^4.7.4"
Expand All @@ -104,8 +103,7 @@
},
"pnpm": {
"patchedDependencies": {
"microbundle@0.15.1": "patches/microbundle@0.15.1.patch",
"@babel/plugin-transform-typescript@7.19.1": "patches/@babel__plugin-transform-typescript@7.19.1.patch"
"microbundle@0.15.1": "patches/microbundle@0.15.1.patch"
},
"overrides": {
"socket.io": "~4.7.2"
Expand Down
28 changes: 28 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# @preact/signals-core

## 1.7.0

### Minor Changes

- [#578](https://github.com/preactjs/signals/pull/578) [`931404e`](https://github.com/preactjs/signals/commit/931404e96338e120464b73e522148389e38eeb2b) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - Allow for passing no argument to the signal and the type to be automatically inferred as `T | undefined`

## 1.6.1

### Patch Changes

- [#558](https://github.com/preactjs/signals/pull/558) [`c8c95ac`](https://github.com/preactjs/signals/commit/c8c95ac7dcbbfe8e97b251a4c3efdec82e72944b) Thanks [@jviide](https://github.com/jviide)! - Restore stricter effect callback & cleanup function types

## 1.6.0

### Minor Changes

- [#525](https://github.com/preactjs/signals/pull/525) [`cb6bdab`](https://github.com/preactjs/signals/commit/cb6bdabbd31b27f8435c7976089fa276da6bfb7a) Thanks [@jviide](https://github.com/jviide)! - Allow setting a signal value inside a computed

### Patch Changes

- [#535](https://github.com/preactjs/signals/pull/535) [`58befba`](https://github.com/preactjs/signals/commit/58befba577d02c5cac5292fda0a599f9708e908b) Thanks [@jviide](https://github.com/jviide)! - Publish packages with provenance statements

- [#529](https://github.com/preactjs/signals/pull/529) [`ec5fe42`](https://github.com/preactjs/signals/commit/ec5fe42850c5dca39da7cf6072558da51cc7fc02) Thanks [@jviide](https://github.com/jviide)! - Document effect cleanups

- [#512](https://github.com/preactjs/signals/pull/512) [`d7f2afa`](https://github.com/preactjs/signals/commit/d7f2afafd7ce0f914cf13d02f87f21ab0c26a74b) Thanks [@jviide](https://github.com/jviide)! - Always reset the evaluation context upon entering an untracked block

- [#531](https://github.com/preactjs/signals/pull/531) [`d17ed0d`](https://github.com/preactjs/signals/commit/d17ed0d2cbc6e57304fa0ed009ecf0a0537fe597) Thanks [@jviide](https://github.com/jviide)! - Add JSDocs for exported core module members

## 1.5.1

### Patch Changes
Expand Down
7 changes: 5 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@preact/signals-core",
"version": "1.5.1",
"version": "1.7.0",
"license": "MIT",
"description": "Manage state with style in every framework",
"keywords": [],
Expand Down Expand Up @@ -42,5 +42,8 @@
"CHANGELOG.md",
"LICENSE",
"README.md"
]
],
"publishConfig": {
"provenance": true
}
}
Loading

0 comments on commit 938ceaa

Please sign in to comment.