bansa 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Atom, DerivedAtom, PrimitiveAtom } from '.';
2
- export declare const useAtom: <Value>(atom: PrimitiveAtom<Value>) => readonly [Value, (value: import(".").AtomUpdater<Value>) => void];
3
2
  export declare const useAtomValue: <Value>(atom: Atom<Value>) => Value;
4
3
  export declare const useAtomState: <Value>(atom: DerivedAtom<Value>) => import(".").AtomState<Value>;
4
+ export declare const useAtom: <Value>(atom: PrimitiveAtom<Value>) => readonly [Value, (newState: Value) => void];
5
5
  export declare const useStateAtom: <Value>(atom: PrimitiveAtom<Value>) => readonly [Value, (newState: Value) => void];
package/dist/react.js CHANGED
@@ -1,13 +1,19 @@
1
1
  import { useState, useSyncExternalStore } from "react";
2
- const useAtom = (atom) => [useSyncExternalStore(atom.watch, atom.get), atom.set];
3
- const useAtomValue = (atom) => useSyncExternalStore(atom.watch, atom.get);
4
- const useAtomState = (atom) => useSyncExternalStore(atom.watch, () => {
5
- try {
6
- atom.get();
7
- } catch (_) {
2
+ const useAtomValue = (atom) => useSyncExternalStore(
3
+ (watcher) => atom.watch(watcher),
4
+ () => atom.get()
5
+ );
6
+ const useAtomState = (atom) => useSyncExternalStore(
7
+ (watcher) => atom.watch(watcher),
8
+ () => {
9
+ try {
10
+ atom.get();
11
+ } catch (_) {
12
+ }
13
+ return atom.state;
8
14
  }
9
- return atom.state;
10
- });
15
+ );
16
+ const useAtom = (atom) => [useAtomValue(atom), (newState) => atom.set(newState)];
11
17
  const useStateAtom = (atom) => {
12
18
  const [state, setState] = useState(() => atom.get());
13
19
  const setStateWithAtom = (newState) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bansa",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -16,11 +16,21 @@
16
16
  "default": "./dist/index.js"
17
17
  }
18
18
  },
19
+ "scripts": {
20
+ "build": "pnpm run \"/^build:.*/\"",
21
+ "build:types": "tsc --noEmit false --emitDeclarationOnly --outDir dist",
22
+ "build:index": "esbuild src/index.ts --mangle-props=^_ --format=esm --target=es2022 --outfile=dist/index.js",
23
+ "build:index-browser": "esbuild src/index.ts --mangle-props=^_ --minify --bundle --format=esm --target=es2022 --platform=browser --outfile=dist/index.browser.js",
24
+ "build:react": "esbuild src/react.tsx --mangle-props=^_ --format=esm --target=es2022 --outfile=dist/react.js",
25
+ "test": "vitest",
26
+ "format": "biome format --write ./src",
27
+ "prepare": "pnpm run build"
28
+ },
19
29
  "devDependencies": {
20
- "@biomejs/biome": "^2.2.2",
21
- "@types/react": "^19.1.12",
30
+ "@biomejs/biome": "^2.2.4",
31
+ "@types/react": "^19.1.15",
22
32
  "@types/react-dom": "^19.1.9",
23
- "esbuild": "^0.25.9",
33
+ "esbuild": "^0.25.10",
24
34
  "typescript": "^5.9.2",
25
35
  "vitest": "^3.2.4"
26
36
  },
@@ -45,19 +55,11 @@
45
55
  "publishConfig": {
46
56
  "access": "public"
47
57
  },
58
+ "packageManager": "pnpm@10.17.1",
48
59
  "homepage": "https://github.com/cgiosy/bansa",
49
60
  "keywords": [
50
61
  "bansa",
51
62
  "state",
52
63
  "react"
53
- ],
54
- "scripts": {
55
- "build": "pnpm run \"/^build:.*/\"",
56
- "build:types": "tsc --noEmit false --emitDeclarationOnly --outDir dist",
57
- "build:index": "esbuild src/index.ts --mangle-props=^_ --format=esm --target=es2022 --outfile=dist/index.js",
58
- "build:index-browser": "esbuild src/index.ts --mangle-props=^_ --minify --bundle --format=esm --target=es2022 --platform=browser --outfile=dist/index.browser.js",
59
- "build:react": "esbuild src/react.tsx --mangle-props=^_ --format=esm --target=es2022 --outfile=dist/react.js",
60
- "test": "vitest",
61
- "format": "biome format --write ./src"
62
- }
63
- }
64
+ ]
65
+ }