@inflector/aura 0.2.12 → 0.2.13

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 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/hooks/react.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAS,MAAM,IAAI,CAAA;AAI3C,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;AAkB5B,wBAAgB,QAAQ,CACtB,IAAI,SAAS,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,EAElF,KAAK,EAAE,IAAI,EACX,OAAO,CAAC,EAAE;IACR,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;CACnE,GAiDc,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAChD;AAED,wBAAgB,SAAS,CACvB,IAAI,SAAS,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,EAElF,KAAK,EAAE,IAAI,EACX,OAAO,EAAE;IACP,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;CACnE,GA+Cc,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CACnD;AAED,eAAO,MAAM,OAAO,GAAI,UAAU,OAAO,CAAC,UAAU,CAAC,OAAO,UAAU,CAAC,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AE,GAAG,CAAC,CAAC,CAAC;;;;;;;;;aAGjF,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,UAAU,GAAG,QAGvC,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import { useStore } from '@nanostores/react';
2
- import { useEffect, useState, useRef } from 'react';
2
+ import { useEffect, useState } from 'react';
3
3
  function deepEqual(a, b) {
4
4
  if (a === b)
5
5
  return true;
@@ -19,20 +19,17 @@ function deepEqual(a, b) {
19
19
  }
20
20
  export function useTable(table, Options) {
21
21
  const [data, setData] = useState([]);
22
- // Use ref to track where clause changes with deep comparison
23
- const whereRef = useRef(Options?.where);
24
22
  const whereString = JSON.stringify(Options?.where);
25
- if (JSON.stringify(whereRef.current) !== whereString) {
26
- whereRef.current = Options?.where;
27
- }
28
23
  useEffect(() => {
29
- // Wait for auth to be initialized
24
+ // 1. Reset data immediately when the where condition changes
25
+ setData([]);
30
26
  const unsubscribe = table.Subscribe((event) => {
31
27
  setData((prev) => {
32
- if (!prev)
33
- return prev;
34
28
  switch (event.action) {
35
29
  case 'Get':
30
+ // 2. Replace the state for 'Get' (initial load)
31
+ // instead of appending to prevent duplicates on reconnections/re-runs
32
+ return Array.isArray(event.data) ? event.data : [event.data];
36
33
  case 'Add':
37
34
  return [...prev, event.data];
38
35
  case 'AddMany':
@@ -52,33 +49,27 @@ export function useTable(table, Options) {
52
49
  return () => {
53
50
  unsubscribe();
54
51
  };
55
- }, [table, whereString]); // <--- include sessionVersion here
52
+ }, [table, whereString]);
56
53
  return data;
57
54
  }
58
55
  export function useRecord(table, Options) {
59
56
  const [data, setData] = useState(undefined);
60
- // Use ref to track where clause changes with deep comparison
61
- const whereRef = useRef(Options.where);
62
57
  const whereString = JSON.stringify(Options.where);
63
- if (JSON.stringify(whereRef.current) !== whereString) {
64
- whereRef.current = Options.where;
65
- }
66
58
  useEffect(() => {
59
+ // Reset data when the query changes
60
+ setData(undefined);
67
61
  const unsubscribe = table.Subscribe((event) => {
68
62
  setData((prev) => {
69
- if (!prev && event.action !== 'Get' && event.action !== 'Add')
70
- return prev;
71
63
  switch (event.action) {
72
64
  case 'Get':
73
65
  case 'Add':
66
+ // For a single record, Get/Add always replaces
74
67
  return event.data;
75
68
  case 'Delete':
76
- // Remove current record if it matches
77
69
  if (event.data.old && deepEqual(event.data.old, prev))
78
70
  return undefined;
79
71
  return prev;
80
72
  case 'Update':
81
- // Replace current record if it matches
82
73
  const update = event.data.find((d) => deepEqual(d.old, prev));
83
74
  if (update)
84
75
  return update.new;
@@ -89,7 +80,7 @@ export function useRecord(table, Options) {
89
80
  });
90
81
  }, Options.where, true);
91
82
  return () => unsubscribe();
92
- }, [table, whereString]); // <--- include sessionVersion
83
+ }, [table, whereString]);
93
84
  return data;
94
85
  }
95
86
  export const useUser = (provider) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inflector/aura",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",