ccstate-react 4.1.0 → 4.3.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # ccstate-react
2
2
 
3
+ ## 4.3.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [89d98a2]
8
+ - ccstate@4.3.0
9
+
10
+ ## 4.2.0
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [023d3a7]
15
+ - ccstate@4.2.0
16
+
3
17
  ## 4.1.0
4
18
 
5
19
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -28,19 +28,19 @@ function useGet(atom) {
28
28
  });
29
29
  }
30
30
 
31
- function useSet(atom) {
31
+ function useSet(signal) {
32
32
  var store = useStore();
33
- if ('write' in atom) {
33
+ if ('write' in signal) {
34
34
  return function () {
35
35
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
36
36
  args[_key] = arguments[_key];
37
37
  }
38
- var ret = store.set.apply(store, [atom].concat(args));
38
+ var ret = store.set.apply(store, [signal].concat(args));
39
39
  return ret;
40
40
  };
41
41
  }
42
42
  return function (value) {
43
- store.set(atom, value);
43
+ store.set(signal, value);
44
44
  };
45
45
  }
46
46
 
package/dist/index.d.cts CHANGED
@@ -1,10 +1,12 @@
1
- import { State, Computed, Updater, Command, Store } from 'ccstate';
1
+ import { State, Computed, Command, StateArg, Store } from 'ccstate';
2
2
  import * as react from 'react';
3
3
 
4
4
  declare function useGet<T>(atom: State<T> | Computed<T>): T;
5
5
 
6
- declare function useSet<T>(atom: State<T>): (value: T | Updater<T>) => void;
7
- declare function useSet<T, ARGS extends unknown[]>(atom: Command<T, ARGS>): (...args: ARGS) => T;
6
+ type ValueSetter<T> = (val: StateArg<T>) => void;
7
+ type CommandInvoker<T, CommandArgs extends unknown[]> = (...args: CommandArgs) => T;
8
+ declare function useSet<T>(signal: State<T>): ValueSetter<T>;
9
+ declare function useSet<T, CommandArgs extends unknown[]>(signal: Command<T, CommandArgs>): CommandInvoker<T, CommandArgs>;
8
10
 
9
11
  declare function useResolved<T>(atom: State<Promise<T>> | Computed<Promise<T>>): T | undefined;
10
12
  declare function useLastResolved<T>(atom: State<Promise<T>> | Computed<Promise<T>>): T | undefined;
package/dist/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
- import { State, Computed, Updater, Command, Store } from 'ccstate';
1
+ import { State, Computed, Command, StateArg, Store } from 'ccstate';
2
2
  import * as react from 'react';
3
3
 
4
4
  declare function useGet<T>(atom: State<T> | Computed<T>): T;
5
5
 
6
- declare function useSet<T>(atom: State<T>): (value: T | Updater<T>) => void;
7
- declare function useSet<T, ARGS extends unknown[]>(atom: Command<T, ARGS>): (...args: ARGS) => T;
6
+ type ValueSetter<T> = (val: StateArg<T>) => void;
7
+ type CommandInvoker<T, CommandArgs extends unknown[]> = (...args: CommandArgs) => T;
8
+ declare function useSet<T>(signal: State<T>): ValueSetter<T>;
9
+ declare function useSet<T, CommandArgs extends unknown[]>(signal: Command<T, CommandArgs>): CommandInvoker<T, CommandArgs>;
8
10
 
9
11
  declare function useResolved<T>(atom: State<Promise<T>> | Computed<Promise<T>>): T | undefined;
10
12
  declare function useLastResolved<T>(atom: State<Promise<T>> | Computed<Promise<T>>): T | undefined;
package/dist/index.js CHANGED
@@ -26,19 +26,19 @@ function useGet(atom) {
26
26
  });
27
27
  }
28
28
 
29
- function useSet(atom) {
29
+ function useSet(signal) {
30
30
  var store = useStore();
31
- if ('write' in atom) {
31
+ if ('write' in signal) {
32
32
  return function () {
33
33
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
34
34
  args[_key] = arguments[_key];
35
35
  }
36
- var ret = store.set.apply(store, [atom].concat(args));
36
+ var ret = store.set.apply(store, [signal].concat(args));
37
37
  return ret;
38
38
  };
39
39
  }
40
40
  return function (value) {
41
- store.set(atom, value);
41
+ store.set(signal, value);
42
42
  };
43
43
  }
44
44
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccstate-react",
3
- "version": "4.1.0",
3
+ "version": "4.3.0",
4
4
  "description": "CCState React Hooks",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,7 +25,7 @@
25
25
  "react": ">=17.0.0"
26
26
  },
27
27
  "dependencies": {
28
- "ccstate": "^4.1.0"
28
+ "ccstate": "^4.3.0"
29
29
  },
30
30
  "peerDependenciesMeta": {
31
31
  "@types/react": {
@@ -55,7 +55,7 @@
55
55
  "shx": "^0.3.4",
56
56
  "signal-timers": "^1.0.4",
57
57
  "vitest": "^2.1.8",
58
- "ccstate": "^4.1.0"
58
+ "ccstate": "^4.3.0"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "rollup -c",
package/src/useSet.ts CHANGED
@@ -1,22 +1,27 @@
1
1
  import { useStore } from './provider';
2
- import type { Command, Updater, State } from 'ccstate';
2
+ import type { Command, State, StateArg } from 'ccstate';
3
3
 
4
- export function useSet<T>(atom: State<T>): (value: T | Updater<T>) => void;
5
- export function useSet<T, ARGS extends unknown[]>(atom: Command<T, ARGS>): (...args: ARGS) => T;
6
- export function useSet<T, ARGS extends unknown[]>(
7
- atom: State<T> | Command<T, ARGS>,
8
- ): ((value: T | Updater<T>) => void) | ((...args: ARGS) => T) {
4
+ type ValueSetter<T> = (val: StateArg<T>) => void;
5
+ type CommandInvoker<T, CommandArgs extends unknown[]> = (...args: CommandArgs) => T;
6
+
7
+ export function useSet<T>(signal: State<T>): ValueSetter<T>;
8
+ export function useSet<T, CommandArgs extends unknown[]>(
9
+ signal: Command<T, CommandArgs>,
10
+ ): CommandInvoker<T, CommandArgs>;
11
+ export function useSet<T, CommandArgs extends unknown[]>(
12
+ signal: State<T> | Command<T, CommandArgs>,
13
+ ): ValueSetter<T> | CommandInvoker<T, CommandArgs> {
9
14
  const store = useStore();
10
15
 
11
- if ('write' in atom) {
12
- return (...args: ARGS): T => {
13
- const ret = store.set(atom, ...args);
16
+ if ('write' in signal) {
17
+ return (...args: CommandArgs): T => {
18
+ const ret = store.set(signal, ...args);
14
19
 
15
20
  return ret;
16
21
  };
17
22
  }
18
23
 
19
- return (value: T | Updater<T>) => {
20
- store.set(atom, value);
24
+ return (value: StateArg<T>) => {
25
+ store.set(signal, value);
21
26
  };
22
27
  }