@ea-lab/reactive-json 2.0.0 → 2.0.1

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,21 +1,21 @@
1
- import { jsx as k } from "react/jsx-runtime";
2
- import { useContext as T, useRef as m, useCallback as q, useEffect as v } from "react";
1
+ import { jsx as _ } from "react/jsx-runtime";
2
+ import { useContext as x, useRef as m, useCallback as q, useEffect as T } from "react";
3
3
  import { ActionDependant as A } from "../../../engine/Actions.js";
4
4
  import { GlobalDataContext as $ } from "../../../engine/GlobalDataContext.js";
5
- import { useStore as G } from "../../../engine/StoreContext.js";
6
- import { TemplateContext as M } from "../../../engine/TemplateContext.js";
7
- import { dataLocationToPath as C } from "../../../engine/TemplateSystem.js";
8
- import { a as N } from "../../../index-BUPRVmV-.js";
9
- import { l as E } from "../../../lodash-CYNxjS-I.js";
10
- const I = (t) => t === "data" ? "" : t && t.startsWith("data.") ? t.substring(5) : t, X = ({ props: t }) => {
11
- const S = T($), d = T(M), e = G(), h = m(void 0), g = m(null), a = m(null), c = m(null), p = m(!1), u = m(0), D = t.mode || "onIdle", R = t.idleDelay || 1e3, b = t.maxRetries ?? 0, L = t.retryDelay ?? 5e3;
5
+ import { useStore as B } from "../../../engine/StoreContext.js";
6
+ import { TemplateContext as G } from "../../../engine/TemplateContext.js";
7
+ import { dataLocationToPath as v } from "../../../engine/TemplateSystem.js";
8
+ import { a as M } from "../../../index-BUPRVmV-.js";
9
+ import { l as C } from "../../../lodash-CYNxjS-I.js";
10
+ const E = (t) => t === "data" ? "" : t && t.startsWith("data.") ? t.substring(5) : t, Q = ({ props: t }) => {
11
+ const S = x($), y = x(G), e = B(), p = m(void 0), d = m(null), a = m(null), u = m(null), g = m(!1), c = m(0), b = t.mode || "onIdle", R = t.idleDelay || 1e3, D = t.maxRetries ?? 0, I = t.retryDelay ?? 5e3;
12
12
  let o = null;
13
13
  try {
14
- o = I(C({
14
+ o = E(v({
15
15
  dataLocation: t.path,
16
- currentPath: d.templatePath,
16
+ currentPath: y.templatePath,
17
17
  globalDataContext: S,
18
- templateContext: d
18
+ templateContext: y
19
19
  }));
20
20
  } catch (r) {
21
21
  console.error("DataSync: Invalid path", t.path, r);
@@ -23,72 +23,78 @@ const I = (t) => t === "data" ? "" : t && t.startsWith("data.") ? t.substring(5)
23
23
  let i = null;
24
24
  if (t.trigger)
25
25
  try {
26
- i = I(C({
26
+ i = E(v({
27
27
  dataLocation: t.trigger,
28
- currentPath: d.templatePath,
28
+ currentPath: y.templatePath,
29
29
  globalDataContext: S,
30
- templateContext: d
30
+ templateContext: y
31
31
  }));
32
32
  } catch (r) {
33
33
  console.error("DataSync: Invalid trigger path", t.trigger, r);
34
34
  }
35
35
  const l = q(async (r) => {
36
- var f, s;
36
+ var f;
37
37
  if (!r || !r.submission_url) {
38
38
  r && console.warn("DataSync: Missing submission_url in data object", r);
39
39
  return;
40
40
  }
41
- if (!p.current && !(u.current > b)) {
42
- p.current = !0, u.current++, h.current = r.data, e.set(`${o}.status`, {
41
+ if (!g.current && !(c.current > D)) {
42
+ g.current = !0, c.current++, p.current = r.data, e.set(`${o}.status`, {
43
43
  type: "info",
44
+ // TODO: translate this.
44
45
  message: "Synchronisation en cours..."
45
46
  });
46
47
  try {
47
- const { submission_url: n } = r, y = (await N.post(n, r)).data;
48
- g.current = y, u.current = 0, e.set(o, y);
48
+ const { submission_url: n } = r, h = (await M.post(n, r)).data;
49
+ d.current = h, c.current = 0, e.set(o, h);
49
50
  } catch (n) {
50
51
  console.error("DataSync error:", n);
51
- const x = {
52
+ const s = (f = n.response) == null ? void 0 : f.data;
53
+ if (s && typeof s == "object" && s.status) {
54
+ d.current = s, c.current = 0, e.set(o, s), g.current = !1;
55
+ return;
56
+ }
57
+ const h = {
52
58
  type: "error",
53
- message: ((s = (f = n.response) == null ? void 0 : f.data) == null ? void 0 : s.message) || n.message || "Erreur inconnue"
59
+ message: n.message || "Unknown error"
54
60
  };
55
- e.set(`${o}.status`, x);
56
- const y = n.response && n.response.status >= 500, P = !n.response && typeof navigator < "u" && !navigator.onLine;
57
- (y || P) && u.current <= b && (c.current = setTimeout(() => {
58
- const _ = e.get(o);
59
- l(_);
60
- }, L));
61
+ e.set(`${o}.status`, h);
62
+ const L = n.response && n.response.status >= 500, P = !n.response && typeof navigator < "u" && !navigator.onLine;
63
+ (L || P) && c.current <= D && (u.current = setTimeout(() => {
64
+ const k = e.get(o);
65
+ l(k);
66
+ }, I));
61
67
  } finally {
62
- p.current = !1;
68
+ g.current = !1;
63
69
  }
64
70
  }
65
- }, [e, o, b]);
66
- return v(() => {
71
+ }, [e, o, D]);
72
+ return T(() => {
67
73
  if (!e || o === null) return;
68
74
  const r = () => {
69
- const s = e.get(o);
70
- if (!s || s === g.current)
75
+ const n = e.get(o);
76
+ if (!n || n === d.current)
71
77
  return;
72
- const n = s.data;
73
- h.current !== void 0 && E.isEqual(n, h.current) || g.current && E.isEqual(n, g.current.data) || (u.current = 0, c.current && (clearTimeout(c.current), c.current = null), D === "immediate" ? l(s) : D === "onIdle" && (a.current && clearTimeout(a.current), a.current = setTimeout(() => {
74
- l(s);
78
+ const s = n.data;
79
+ p.current !== void 0 && C.isEqual(s, p.current) || d.current && C.isEqual(s, d.current.data) || (c.current = 0, u.current && (clearTimeout(u.current), u.current = null), b === "immediate" ? l(n) : b === "onIdle" && (a.current && clearTimeout(a.current), a.current = setTimeout(() => {
80
+ l(n);
75
81
  }, R)));
76
82
  }, f = e.subscribe(o, r);
77
83
  return () => {
78
- f(), a.current && clearTimeout(a.current), c.current && clearTimeout(c.current);
84
+ f(), a.current && clearTimeout(a.current), u.current && clearTimeout(u.current);
79
85
  };
80
- }, [e, o, D, R, l]), v(() => {
86
+ }, [e, o, b, R, l]), T(() => {
81
87
  if (!e || i === null) return;
82
88
  const r = () => {
83
89
  if (e.get(i) === !0) {
84
- e.set(i, !1), a.current && (clearTimeout(a.current), a.current = null), u.current = 0;
85
- const n = e.get(o);
86
- l(n);
90
+ e.set(i, !1), a.current && (clearTimeout(a.current), a.current = null), c.current = 0;
91
+ const s = e.get(o);
92
+ l(s);
87
93
  }
88
94
  }, f = e.subscribe(i, r);
89
95
  return () => f();
90
- }, [e, i, o, l]), /* @__PURE__ */ k(A, { ...t });
96
+ }, [e, i, o, l]), /* @__PURE__ */ _(A, { ...t });
91
97
  };
92
98
  export {
93
- X as DataSync
99
+ Q as DataSync
94
100
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ea-lab/reactive-json",
3
3
  "private": false,
4
- "version": "2.0.0",
4
+ "version": "2.0.1",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",