synstate-preact-hooks 6.2.0 → 7.0.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.
@@ -1,14 +1,14 @@
1
1
  import type { Observable } from 'synstate';
2
2
  /**
3
- * Subscribes `subscriptionFn` to `observable$` while the component is
4
- * mounted, and unsubscribes when it unmounts.
3
+ * Subscribes `subscriptionFn` to `observable$` while the component is mounted,
4
+ * and unsubscribes when it unmounts.
5
5
  *
6
- * Each value is passed to the `subscriptionFn` of the latest render, so it
7
- * sees the current props and state; a new function on every render does not
6
+ * Each value is passed to the `subscriptionFn` of the latest render, so it sees
7
+ * the current props and state; a new function on every render does not
8
8
  * re-subscribe. Passing a different Observable moves the subscription to it,
9
9
  * so pass one that keeps its identity across renders (made outside the
10
- * component, or memoized): one built during render is subscribed again, and
11
- * an initialized one calls `subscriptionFn` again, on every render.
10
+ * component, or memoized): one built during render is subscribed again, and an
11
+ * initialized one calls `subscriptionFn` again, on every render.
12
12
  *
13
13
  * @param observable$ The Observable to subscribe to.
14
14
  * @param subscriptionFn Called with each value `observable$` emits.
@@ -1 +1 @@
1
- {"version":3,"file":"use-observable-effect.d.mts","sourceRoot":"","sources":["../src/use-observable-effect.mts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,eACtB,UAAU,CAAC,CAAC,CAAC,kBACV,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,KAC7B,IAkBF,CAAC"}
1
+ {"version":3,"file":"use-observable-effect.d.mts","sourceRoot":"","sources":["../src/use-observable-effect.mts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,eACtB,UAAU,CAAC,CAAC,CAAC,kBACV,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,KAC7B,IAiBF,CAAC"}
@@ -18,7 +18,6 @@ export const useObservableEffect = (observable$, subscriptionFn) => {
18
18
 
19
19
 
20
20
 
21
-
22
21
  mut_subscriptionFnRef.current = subscriptionFn;
23
22
  Preact.useEffect(() => {
24
23
  const s = observable$.subscribe((v) => {
@@ -1 +1 @@
1
- {"version":3,"file":"use-observable-effect.mjs","sourceRoot":"","sources":["../src/use-observable-effect.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AAGvC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,WAA0B,EAC1B,cAA8B,EACxB,EAAE;IACR,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAE5D,uEAAuE;IACvE,0EAA0E;IAC1E,uEAAuE;IACvE,eAAe;IACf,qBAAqB,CAAC,OAAO,GAAG,cAAc,CAAC;IAE/C,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE;QACpB,MAAM,CAAC,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE;YACpC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,CAAC,CAAC,WAAW,EAAE,CAAC;QAClB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC"}
1
+ {"version":3,"file":"use-observable-effect.mjs","sourceRoot":"","sources":["../src/use-observable-effect.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AAGvC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,WAA0B,EAC1B,cAA8B,EACxB,EAAE;IACR,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAE5D,6EAA6E;IAC7E,6EAA6E;IAC7E,2EAA2E;IAC3E,qBAAqB,CAAC,OAAO,GAAG,cAAc,CAAC;IAE/C,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE;QACpB,MAAM,CAAC,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE;YACpC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,CAAC,CAAC,WAAW,EAAE,CAAC;QAClB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-value-as-observable.d.mts","sourceRoot":"","sources":["../src/use-value-as-observable.mts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,UAAU,EAEhB,MAAM,UAAU,CAAC;AAElB,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAU,CAAC,KAAG,UAAU,CAAC,CAAC,CA2B/D,CAAC"}
1
+ {"version":3,"file":"use-value-as-observable.d.mts","sourceRoot":"","sources":["../src/use-value-as-observable.mts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,UAAU,EAEhB,MAAM,UAAU,CAAC;AAElB,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAU,CAAC,KAAG,UAAU,CAAC,CAAC,CAwB/D,CAAC"}
@@ -8,12 +8,11 @@ export const useValueAsObservable = (input) => {
8
8
  () => () => {
9
9
  state.complete();
10
10
  }, []);
11
- const setState = Preact.useCallback((nextState) => {
12
- sourceObservable.next(nextState);
13
- return nextState;
14
- }, []);
15
11
  Preact.useEffect(() => {
16
- setState(input);
12
+
13
+ if (!Object.is(state.getSnapshot().value, input)) {
14
+ sourceObservable.next(input);
15
+ }
17
16
  }, [input]);
18
17
  return state;
19
18
  };
@@ -1 +1 @@
1
- {"version":3,"file":"use-value-as-observable.mjs","sourceRoot":"","sources":["../src/use-value-as-observable.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EACL,MAAM,EACN,gBAAgB,GAGjB,MAAM,UAAU,CAAC;AAElB,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAK,KAAQ,EAAiB,EAAE;IAClE,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAsB,MAAM,EAAE,EAAE,CAAC,CAAC;IAEzE,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAC1B,GAAG,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,EACpD,EAAE,CACH,CAAC;IAEF,MAAM,CAAC,SAAS;IACd,+DAA+D;IAC/D,GAAG,EAAE,CAAC,GAAG,EAAE;QACT,KAAK,CAAC,QAAQ,EAAE,CAAC;IACnB,CAAC,EACD,EAAE,CACH,CAAC;IAEF,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,SAAY,EAAK,EAAE;QACtD,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAEjC,OAAO,SAAS,CAAC;IACnB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE;QACpB,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
1
+ {"version":3,"file":"use-value-as-observable.mjs","sourceRoot":"","sources":["../src/use-value-as-observable.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EACL,MAAM,EACN,gBAAgB,GAGjB,MAAM,UAAU,CAAC;AAElB,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAK,KAAQ,EAAiB,EAAE;IAClE,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAsB,MAAM,EAAE,EAAE,CAAC,CAAC;IAEzE,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAC1B,GAAG,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,EACpD,EAAE,CACH,CAAC;IAEF,MAAM,CAAC,SAAS;IACd,+DAA+D;IAC/D,GAAG,EAAE,CAAC,GAAG,EAAE;QACT,KAAK,CAAC,QAAQ,EAAE,CAAC;IACnB,CAAC,EACD,EAAE,CACH,CAAC;IAEF,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE;QACpB,8DAA8D;QAC9D,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC;YACjD,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "synstate-preact-hooks",
3
- "version": "6.2.0",
3
+ "version": "7.0.0",
4
4
  "description": "Type-safe State Management Library for TypeScript/JavaScript",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,24 +28,24 @@
28
28
  "LICENSE"
29
29
  ],
30
30
  "dependencies": {
31
- "synstate": "6.1.1",
32
- "ts-data-forge": "^14.10.0",
31
+ "synstate": "7.0.0",
32
+ "ts-data-forge": "^14.11.0",
33
33
  "ts-type-forge": "^9.2.2"
34
34
  },
35
35
  "devDependencies": {
36
- "@sumi-lang/cli": "0.1.3",
36
+ "@sumi-lang/cli": "0.1.6",
37
37
  "@testing-library/preact": "3.2.4",
38
38
  "@vitest/browser-playwright": "5.0.5",
39
- "eslint-config-typed": "7.2.1",
40
- "eslint-plugin-ts-data-forge": "0.10.6",
41
- "eslint-plugin-ts-fortress": "1.3.11",
42
- "eslint-plugin-ts-type-forge": "0.8.16",
39
+ "eslint-config-typed": "7.4.0",
40
+ "eslint-plugin-ts-data-forge": "0.10.9",
41
+ "eslint-plugin-ts-fortress": "1.3.13",
42
+ "eslint-plugin-ts-type-forge": "0.8.18",
43
43
  "playwright": "1.64.1",
44
44
  "preact": "10.29.8",
45
45
  "prettier": "3.9.10",
46
46
  "prettier-plugin-organize-imports": "4.3.0",
47
47
  "prettier-plugin-packagejson": "3.0.2",
48
- "ts-repo-utils": "10.7.1"
48
+ "ts-repo-utils": "10.7.2"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "preact": ">=10.0.0"
@@ -2,15 +2,15 @@ import * as Preact from 'preact/hooks';
2
2
  import type { Observable } from 'synstate';
3
3
 
4
4
  /**
5
- * Subscribes `subscriptionFn` to `observable$` while the component is
6
- * mounted, and unsubscribes when it unmounts.
5
+ * Subscribes `subscriptionFn` to `observable$` while the component is mounted,
6
+ * and unsubscribes when it unmounts.
7
7
  *
8
- * Each value is passed to the `subscriptionFn` of the latest render, so it
9
- * sees the current props and state; a new function on every render does not
8
+ * Each value is passed to the `subscriptionFn` of the latest render, so it sees
9
+ * the current props and state; a new function on every render does not
10
10
  * re-subscribe. Passing a different Observable moves the subscription to it,
11
11
  * so pass one that keeps its identity across renders (made outside the
12
- * component, or memoized): one built during render is subscribed again, and
13
- * an initialized one calls `subscriptionFn` again, on every render.
12
+ * component, or memoized): one built during render is subscribed again, and an
13
+ * initialized one calls `subscriptionFn` again, on every render.
14
14
  *
15
15
  * @param observable$ The Observable to subscribe to.
16
16
  * @param subscriptionFn Called with each value `observable$` emits.
@@ -21,10 +21,9 @@ export const useObservableEffect = <A,>(
21
21
  ): void => {
22
22
  const mut_subscriptionFnRef = Preact.useRef(subscriptionFn);
23
23
 
24
- // Stored as the component renders, before any effect of the commit can
25
- // emit. Preact has no concurrent rendering; only a render that throws (to
26
- // an error boundary, or to suspend) leaves its function here until the
27
- // next render.
24
+ // Stored as the component renders, before any effect of the commit can emit.
25
+ // Preact has no concurrent rendering; only a render that throws (to an error
26
+ // boundary, or to suspend) leaves its function here until the next render.
28
27
  mut_subscriptionFnRef.current = subscriptionFn;
29
28
 
30
29
  Preact.useEffect(() => {
@@ -22,14 +22,11 @@ export const useValueAsObservable = <A,>(input: A): Observable<A> => {
22
22
  [],
23
23
  );
24
24
 
25
- const setState = Preact.useCallback((nextState: A): A => {
26
- sourceObservable.next(nextState);
27
-
28
- return nextState;
29
- }, []);
30
-
31
25
  Preact.useEffect(() => {
32
- setState(input);
26
+ // The observable already holds the value it was created with.
27
+ if (!Object.is(state.getSnapshot().value, input)) {
28
+ sourceObservable.next(input);
29
+ }
33
30
  }, [input]);
34
31
 
35
32
  return state;