diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4616466..c6d427c 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -3,8 +3,6 @@ on: push: tags: - v* -env: - CI: true jobs: release: @@ -13,22 +11,16 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup Node.js environment - uses: actions/setup-node@v4 + - name: Setup Bun + uses: oven-sh/setup-bun@v2 with: - node-version: 22 - cache: "npm" + bun-version: latest - name: Install Dependencies - run: npm install - - # Ensure a new version doesn't get published to npm if it doesn't - # pass all required checks/validation: - - name: Run Checks - run: npm run typecheck && npm run prettier:ci && npm run eslint + run: bun install - name: Build - run: npm run build + run: bun run build - name: Publish to npm uses: laserware/propellant@v1.0.2 diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 458fbec..29faa20 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -1,6 +1,4 @@ -# Simple workflow for deploying static content to GitHub Pages name: Deploy Documentation Site - on: push: branches: [ "main" ] @@ -8,7 +6,6 @@ on: # Allows you to run this workflow manually from the Actions tab: workflow_dispatch: -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages: permissions: contents: read pages: write @@ -32,22 +29,22 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Setup Node.js environment - uses: actions/setup-node@v4 + - name: Setup Bun + uses: oven-sh/setup-bun@v2 with: - node-version: 22 + bun-version: latest - - name: Install dependencies - run: npm install + - name: Install Dependencies + run: bun install - - name: Build static files + - name: Build Static Files id: build - run: npm run docs:generate + run: bun run docs:generate - name: Setup Pages uses: actions/configure-pages@v5 - - name: Upload artifact + - name: Upload Artifact uses: actions/upload-pages-artifact@v3 with: path: "site" diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index efc55f4..e235b5d 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -1,7 +1,5 @@ name: Validate on: [push] -env: - CI: true jobs: check: @@ -10,20 +8,19 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup Node.js environment - uses: actions/setup-node@v4 + - name: Setup Bun + uses: oven-sh/setup-bun@v2 with: - node-version: 22 - cache: "npm" + bun-version: latest - - name: Install dependencies - run: npm install + - name: Install Dependencies + run: bun install - - name: ESLint - run: npm run eslint - - - name: Check Formatting - run: npm run prettier:ci + - name: Run Biome Checks + run: bun run ci - name: Check Types - run: npm run typecheck + run: bun run check:types + + - name: Run Unit Tests + run: bun test diff --git a/.run/Build.run.xml b/.run/Build.run.xml new file mode 100644 index 0000000..331584f --- /dev/null +++ b/.run/Build.run.xml @@ -0,0 +1,12 @@ + + + + + + + * + * + * ``` + */ +export function useDispatch(): (action: UnknownAction) => void { + const store = getStoreContext(); + + return (action: UnknownAction): void => { + store.dispatch(action); + }; +} + +/** + * Creates an object with a `value` property which contains the current value + * of the specified `selector`. + * + * @template R Return value from the `selector`. + * @template S Redux state definition. + * + * @param selector Selector function either returned by [`createSelector`](https://redux-toolkit.js.org/api/createSelector) + * or a simple state accessor. + * @param args Additional args to pass to selector. + * + * @returns An object with a reactive `value` property that represents the return + * value of the specified `selector`. + * + * @example + * ```html + * + * + * + * ``` + */ +export function useSelector( + selector: Selector, + ...args: any[] +): { readonly value: R } { + const getState = getGetStateContext(); + + return { + get value(): R { + return selector(getState(), ...args); + }, + }; +} + +/** + * Returns a function to get the current state from the Redux store in context. + * + * Note that we can't just return the state here because we probably want to + * access it dynamically, and Svelte won't let you do that within a function + * (since the context must be initialized with the component loads). + * + * @template S Redux state definition. + * + * @returns Function that returns Redux state. + * + * @example + * ```html + * + * + * + * ``` + */ +export function useState(): () => S { + return getGetStateContext(); +} + +/** + * Gets the Redux store from the Svelte context. Note that you should normally + * not need to use this unless you need to call `replaceReducer` or perform + * some other operation that requires access to the entire store. + * + * @template S Redux state definition. + * + * @returns The Redux store from Svelte context. + * + * @example + * ```html + * + * + * + * ``` + */ +export function useStore(): Store { + return getStoreContext(); +} diff --git a/src/index.ts b/src/index.ts index 546a79e..a486b0c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,8 @@ import type { SvelteComponent } from "svelte"; -export { provide } from "./provide.svelte.js"; -export { useDispatch } from "./useDispatch.js"; -export { useSelector } from "./useSelector.js"; -export { useState } from "./useState.js"; -export { useStore } from "./useStore.js"; +export { useDispatch, useSelector, useState, useStore } from "./hooks.js"; export { default as Provider } from "./Provider.svelte"; +export { provide } from "./provide.svelte.js"; /** * This is a type alias for the `` component. Do _not_ use this diff --git a/src/provide.svelte.ts b/src/provide.svelte.ts index d905751..2475ec4 100644 --- a/src/provide.svelte.ts +++ b/src/provide.svelte.ts @@ -1,4 +1,4 @@ -import type { Store } from "@laserware/stasis"; +import type { Store } from "@reduxjs/toolkit"; import { getStateContextKey, storeContextKey } from "./context.js"; @@ -40,7 +40,7 @@ import { getStateContextKey, storeContextKey } from "./context.js"; * * **With Additional Context Entries** * - * If you need to add other items to Svelte context, just use the return value + * If you need to add other items to the Svelte context, use the return value * of `provide`: * * ```ts diff --git a/src/useDispatch.ts b/src/useDispatch.ts deleted file mode 100644 index 0a609e8..0000000 --- a/src/useDispatch.ts +++ /dev/null @@ -1,33 +0,0 @@ -import type { UnknownAction } from "@laserware/stasis"; - -import { getStoreContext } from "./context.js"; - -/** - * Gets the `dispatch` function from the Redux store in context. - * - * @returns Dispatch function that can be called with a Redux action. - * - * @example - * ```html - * - * - * - * ``` - */ -export function useDispatch(): (action: UnknownAction) => void { - const store = getStoreContext(); - - return (action: UnknownAction): void => { - store.dispatch(action); - }; -} diff --git a/src/useSelector.ts b/src/useSelector.ts deleted file mode 100644 index dc81518..0000000 --- a/src/useSelector.ts +++ /dev/null @@ -1,47 +0,0 @@ -import type { Selector } from "@laserware/stasis"; - -import { getGetStateContext } from "./context.js"; - -/** - * Creates an object with a `value` property which contains the current value - * of the specified `selector`. - * - * @template R Return value from the `selector`. - * @template S Redux state definition. - * - * @param selector Selector function either returned by [`createSelector`](https://redux-toolkit.js.org/api/createSelector) - * or a simple state accessor. - * @param args Additional args to pass to selector. - * - * @returns An object with a reactive `value` property that represents the return - * value of the specified `selector`. - * - * @example - * ```html - * - * - * - * ``` - */ -export function useSelector( - selector: Selector, - ...args: any[] -): { readonly value: R } { - const getState = getGetStateContext(); - - return { - get value(): R { - return selector(getState(), ...args); - }, - }; -} diff --git a/src/useState.ts b/src/useState.ts deleted file mode 100644 index e78f406..0000000 --- a/src/useState.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { getStoreContext } from "./context.js"; - -/** - * Returns a function to get the current state from the Redux store in context. - * - * Note that we can't just return state here because we probably want to - * access it dynamically and Svelte won't let you do that within a function - * (since the context must be initialized with the component loads). - * - * @template S Redux state definition. - * - * @returns Function that returns Redux state. - * - * @example - * ```html - * - * - * - * ``` - */ -export function useState(): () => S { - const store = getStoreContext(); - - return () => store.getState(); -} diff --git a/src/useStore.ts b/src/useStore.ts deleted file mode 100644 index 6eea8cd..0000000 --- a/src/useStore.ts +++ /dev/null @@ -1,35 +0,0 @@ -import type { Store } from "@laserware/stasis"; - -import { getStoreContext } from "./context.js"; - -/** - * Gets the Redux store from Svelte context. Note that you should normally - * not need to use this unless you need to call `replaceReducer` or perform - * some other operation that requires access to the entire store. - * - * @template S Redux state definition. - * - * @returns The Redux store from Svelte context. - * - * @example - * ```html - * - * - * - * ``` - */ -export function useStore(): Store { - return getStoreContext(); -} diff --git a/tsconfig.json b/tsconfig.json index 4727449..2e1964b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,8 @@ { "$schema": "https://json.schemastore.org/tsconfig", "compilerOptions": { - "allowSyntheticDefaultImports": true, "declaration": true, "declarationMap": false, - "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "lib": ["DOM", "ESNext"], "module": "NodeNext", @@ -15,10 +13,10 @@ "skipLibCheck": true, "sourceMap": false, "strict": true, + "strictNullChecks": true, "target": "ESNext", "verbatimModuleSyntax": true }, - "include": ["./src/**/*.ts"], - "exclude": ["dist", "node_modules"], - "references": [{ "path": "./tsconfig.node.json" }] + "include": ["src"], + "exclude": ["dist", "node_modules"] } diff --git a/tsconfig.node.json b/tsconfig.node.json deleted file mode 100644 index c38afb1..0000000 --- a/tsconfig.node.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/tsconfig", - "compilerOptions": { - "composite": true - }, - "include": ["./tsup.config.ts"] -} diff --git a/typedoc.json b/typedoc.json index 97b642b..604d878 100644 --- a/typedoc.json +++ b/typedoc.json @@ -1,4 +1,5 @@ { + "$schema": "https://typedoc.org/schema.json", "cleanOutputDir": true, "entryPoints": ["./src/index.ts"], "exclude": ["**/**test.ts"],