Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up prettier #20

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ concurrency:

jobs:
test:
name: "Test ${{ matrix.testenv.name }}"
name: 'Test ${{ matrix.testenv.name }}'
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
strategy:
matrix:
testenv:
- { name: "Node", args: '' }
- { name: "Chrome", args: '--browser.name=chrome --browser.headless' }
- { name: "Firefox", args: '--browser.name=firefox --browser.headless' }
testenv:
- {name: 'Node', args: ''}
- {name: 'Chrome', args: '--browser.name=chrome --browser.headless'}
- {name: 'Firefox', args: '--browser.name=firefox --browser.headless'}

steps:
- uses: actions/checkout@v4
- uses: wyvox/action-setup-pnpm@v3
- run: pnpm install --no-lockfile
- run: pnpm lint
- run: pnpm build
- run: pnpm vitest ${{ matrix.testenv.args }}
12 changes: 6 additions & 6 deletions .github/workflows/plan-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ concurrency:

jobs:
check-plan:
name: "Check Release Plan"
name: 'Check Release Plan'
runs-on: ubuntu-latest
outputs:
command: ${{ steps.check-release.outputs.command }}
Expand Down Expand Up @@ -52,14 +52,14 @@ jobs:
ref: 'main'
- uses: wyvox/action-setup-pnpm@v3
- run: pnpm install --frozen-lockfile
- name: "Generate Explanation and Prep Changelogs"

- name: 'Generate Explanation and Prep Changelogs'
id: explanation
run: |
set +e

pnpm release-plan prepare 2> >(tee -a release-plan-stderr.txt >&2)


if [ $? -ne 0 ]; then
echo 'text<<EOF' >> $GITHUB_OUTPUT
Expand All @@ -77,7 +77,7 @@ jobs:
- uses: peter-evans/create-pull-request@v6
with:
commit-message: "Prepare Release using 'release-plan'"
labels: "internal"
labels: 'internal'
branch: release-preview
title: Prepare Release
body: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ concurrency:

jobs:
check-plan:
name: "Check Release Plan"
name: 'Check Release Plan'
runs-on: ubuntu-latest
outputs:
command: ${{ steps.check-release.outputs.command }}
Expand All @@ -34,7 +34,7 @@ jobs:
run: if git diff --name-only HEAD HEAD~1 | grep -w -q ".release-plan.json"; then echo "command=release"; fi >> $GITHUB_OUTPUT

publish:
name: "NPM Publish"
name: 'NPM Publish'
runs-on: ubuntu-latest
needs: check-plan
if: needs.check-plan.outputs.command == 'release'
Expand All @@ -51,7 +51,7 @@ jobs:
- run: pnpm install --frozen-lockfile
- name: npm publish
run: pnpm release-plan publish

env:
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
10 changes: 10 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"embeddedLanguageFormatting": "off",
"singleQuote": true,
"semi": true,
"quoteProps": "preserve",
"bracketSpacing": false
}
10 changes: 6 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
signal-polyfill 0.1.1 (patch)

#### :house: Internal
* `signal-polyfill`
* [#6](https://github.com/proposal-signals/signal-polyfill/pull/6) Fix repo references ([@NullVoxPopuli](https://github.com/NullVoxPopuli))
* [#4](https://github.com/proposal-signals/signal-polyfill/pull/4) Setup release automation ([@NullVoxPopuli](https://github.com/NullVoxPopuli))
* [#1](https://github.com/proposal-signals/signal-polyfill/pull/1) Fix CI ([@NullVoxPopuli](https://github.com/NullVoxPopuli))

- `signal-polyfill`
- [#6](https://github.com/proposal-signals/signal-polyfill/pull/6) Fix repo references ([@NullVoxPopuli](https://github.com/NullVoxPopuli))
- [#4](https://github.com/proposal-signals/signal-polyfill/pull/4) Setup release automation ([@NullVoxPopuli](https://github.com/NullVoxPopuli))
- [#1](https://github.com/proposal-signals/signal-polyfill/pull/1) Fix CI ([@NullVoxPopuli](https://github.com/NullVoxPopuli))

#### Committers: 1

- [@NullVoxPopuli](https://github.com/NullVoxPopuli)
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Signal Polyfill

## ⚠️ This polyfill is a preview of an in-progress proposal and could change at any time. Do not use this in production. ⚠️
## ⚠️ This polyfill is a preview of an in-progress proposal and could change at any time. Do not use this in production. ⚠️

A "signal" is [a proposed first-class JavaScript data type](https://github.com/tc39/proposal-signals) that enables one-way data flow through cells of state or computations derived from other state/computations.

Expand All @@ -10,16 +10,16 @@ This is a polyfill for the `Signal` API.

### Using signals

* Use `Signal.State(value)` to create a single "cell" of data that can flow through the unidirectional state graph.
* Use `Signal.Computed(callback)` to define a computation based on state or other computations flowing through the graph.
- Use `Signal.State(value)` to create a single "cell" of data that can flow through the unidirectional state graph.
- Use `Signal.Computed(callback)` to define a computation based on state or other computations flowing through the graph.

```js
import { Signal } from "signal-polyfill";
import { effect } from "./effect.js";

const counter = new Signal.State(0);
const isEven = new Signal.Computed(() => (counter.get() & 1) == 0);
const parity = new Signal.Computed(() => isEven.get() ? "even" : "odd");
const parity = new Signal.Computed(() => (isEven.get() ? "even" : "odd"));

effect(() => console.log(parity.get())); // Console logs "even" immediately.
setInterval(() => counter.set(counter.get() + 1), 1000); // Changes the counter every 1000ms.
Expand All @@ -44,11 +44,11 @@ Depending on how the effect is implemented, the above code could result in an in

### Creating a simple effect

* You can use `Signal.subtle.Watch(callback)` combined with `Signal.Computed(callback)` to create a simple _effect_ implementation.
* The `Signal.subtle.Watch` `callback` is invoked synchronously when a watched signal becomes dirty.
* To batch effect updates, library authors are expected to implement their own schedulers.
* Use `Signal.subtle.Watch#getPending()` to retrieve an array of dirty signals.
* Calling `Signal.subtle.Watch#watch()` with no arguments will re-watch the list of tracked signals again.
- You can use `Signal.subtle.Watch(callback)` combined with `Signal.Computed(callback)` to create a simple _effect_ implementation.
- The `Signal.subtle.Watch` `callback` is invoked synchronously when a watched signal becomes dirty.
- To batch effect updates, library authors are expected to implement their own schedulers.
- Use `Signal.subtle.Watch#getPending()` to retrieve an array of dirty signals.
- Calling `Signal.subtle.Watch#watch()` with no arguments will re-watch the list of tracked signals again.

```js
import { Signal } from "signal-polyfill";
Expand All @@ -64,7 +64,7 @@ const w = new Signal.subtle.Watcher(() => {

function processPending() {
needsEnqueue = true;

for (const s of w.getPending()) {
s.get();
}
Expand All @@ -74,15 +74,15 @@ function processPending() {

export function effect(callback) {
let cleanup;

const computed = new Signal.Computed(() => {
typeof cleanup === "function" && cleanup();
cleanup = callback();
});

w.watch(computed);
computed.get();

return () => {
w.unwatch(computed);
typeof cleanup === "function" && cleanup();
Expand Down Expand Up @@ -112,7 +112,7 @@ export function signal(target) {
set(value) {
get.call(this).set(value);
},

init(value) {
return new Signal.State(value);
},
Expand Down
16 changes: 8 additions & 8 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ Releases in this repo are mostly automated using [release-plan](https://github.c

## Preparation

Since the majority of the actual release process is automated, the remaining tasks before releasing are:
Since the majority of the actual release process is automated, the remaining tasks before releasing are:

- correctly labeling **all** pull requests that have been merged since the last release
- updating pull request titles so they make sense to our users
- correctly labeling **all** pull requests that have been merged since the last release
- updating pull request titles so they make sense to our users

Some great information on why this is important can be found at [keepachangelog.com](https://keepachangelog.com/en/1.1.0/), but the overall
guiding principle here is that changelogs are for humans, not machines.

When reviewing merged PR's the labels to be used are:

* breaking - Used when the PR is considered a breaking change.
* enhancement - Used when the PR adds a new feature or enhancement.
* bug - Used when the PR fixes a bug included in a previous release.
* documentation - Used when the PR adds or updates documentation.
* internal - Internal changes or things that don't fit in any other category.
- breaking - Used when the PR is considered a breaking change.
- enhancement - Used when the PR adds a new feature or enhancement.
- bug - Used when the PR fixes a bug included in a previous release.
- documentation - Used when the PR adds or updates documentation.
- internal - Internal changes or things that don't fit in any other category.

**Note:** `release-plan` requires that **all** PRs are labeled. If a PR doesn't fit in a category it's fine to label it as `internal`

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"build": "tsc && vite build",
"dev": "vite",
"prepack": "npm run build",
"lint": "prettier --check .",
"lint:fix": "prettier --write .",
"test": "vitest"
},
"devDependencies": {
Expand Down
13 changes: 10 additions & 3 deletions src/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@
*/

import {defaultEquals, ValueEqualityFn} from './equality.js';
import {consumerAfterComputation, consumerBeforeComputation, producerAccessed, producerUpdateValueVersion, REACTIVE_NODE, ReactiveNode, SIGNAL} from './graph.js';

import {
consumerAfterComputation,
consumerBeforeComputation,
producerAccessed,
producerUpdateValueVersion,
REACTIVE_NODE,
ReactiveNode,
SIGNAL,
} from './graph.js';

/**
* A computation, which derives a value from a declarative reactive expression.
Expand Down Expand Up @@ -36,7 +43,7 @@ export interface ComputedNode<T> extends ReactiveNode {
equal: ValueEqualityFn<T>;
}

export type ComputedGetter<T> = (() => T)&{
export type ComputedGetter<T> = (() => T) & {
[SIGNAL]: ComputedNode<T>;
};

Expand Down
2 changes: 1 addition & 1 deletion src/equality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ export type ValueEqualityFn<T> = (a: T, b: T) => boolean;
*/
export function defaultEquals<T>(a: T, b: T) {
return Object.is(a, b);
}
}
2 changes: 1 addition & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export function throwInvalidWriteToSignalError() {

export function setThrowInvalidWriteToSignalError(fn: () => never): void {
throwInvalidWriteToSignalErrorFn = fn;
}
}
Loading
Loading