@civet/events 2.0.3 → 3.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.
@@ -0,0 +1,21 @@
1
+ import { GenericDataProviderImplementation } from '@civet/core';
2
+ import { GenericEventReceiver, InferEvent, InferOptions } from './EventReceiver';
3
+ type EventProps<EventReceiverI extends GenericEventReceiver, OptionsI extends InferOptions<EventReceiverI> = InferOptions<EventReceiverI>, EventI extends InferEvent<EventReceiverI> = InferEvent<EventReceiverI>> = {
4
+ events?: {
5
+ /** EventReceiver to be used */
6
+ eventReceiver?: EventReceiverI;
7
+ /** Disables the event handler */
8
+ disabled?: boolean;
9
+ /** Options for the EventReceiver */
10
+ options?: OptionsI;
11
+ /** Callback to filter events and handle your own event logic - if true is returned, the event does not cause the resource to update */
12
+ onEvent?: (event: EventI) => boolean;
13
+ /** Provides information on when the resource has been requested to update - events contains the events that lead to the update */
14
+ onNotify?: (next: {
15
+ request: string;
16
+ revision: string;
17
+ }, events: EventI[]) => void;
18
+ } | boolean;
19
+ };
20
+ declare const eventPlugin: import('@civet/core').DataProviderPlugin<GenericDataProviderImplementation, unknown, EventProps<GenericEventReceiver, unknown, unknown>, unknown, unknown, unknown>;
21
+ export default eventPlugin;
package/dist/main.js CHANGED
@@ -1,6 +1,6 @@
1
- import { createContext as R, useContext as j, useMemo as q, useState as y, useEffect as S } from "react";
2
- import { jsx as C, Fragment as w } from "react/jsx-runtime";
3
- import { useResourceContext as D } from "@civet/core";
1
+ import { createContext as R, useContext as j, useMemo as q, useState as y, useEffect as D } from "react";
2
+ import { jsx as E, Fragment as S } from "react/jsx-runtime";
3
+ import { useResourceContext as w } from "@civet/core";
4
4
  const l = R({});
5
5
  l.displayName = "Events.ConfigContext";
6
6
  const J = l.Consumer, _ = () => j(l);
@@ -33,14 +33,14 @@ function Q({
33
33
  children: e
34
34
  }) {
35
35
  const t = q(() => ({ eventReceiver: r }), [r]);
36
- return /* @__PURE__ */ C(l.Provider, { value: t, children: e });
36
+ return /* @__PURE__ */ E(l.Provider, { value: t, children: e });
37
37
  }
38
38
  function H(r) {
39
39
  return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
40
40
  }
41
- var d, E;
41
+ var g, C;
42
42
  function A() {
43
- return E || (E = 1, d = function r(e, t) {
43
+ return C || (C = 1, g = function r(e, t) {
44
44
  if (e === t) return !0;
45
45
  if (e && t && typeof e == "object" && typeof t == "object") {
46
46
  if (e.constructor !== t.constructor) return !1;
@@ -64,7 +64,7 @@ function A() {
64
64
  return !0;
65
65
  }
66
66
  return e !== e && t !== t;
67
- }), d;
67
+ }), g;
68
68
  }
69
69
  var M = A();
70
70
  const P = /* @__PURE__ */ H(M);
@@ -76,23 +76,23 @@ function B({
76
76
  onEvent: o,
77
77
  onNotify: s
78
78
  }) {
79
- const u = _(), a = r || u.eventReceiver, O = D(), f = e || O, [c, b] = y(f);
80
- f?.request !== c?.request && b(f);
79
+ const u = _(), a = r || u.eventReceiver, b = w(), f = e || b, [c, O] = y(f);
80
+ f?.request !== c?.request && O(f);
81
81
  const [p, h] = y(n);
82
82
  P(p, n) || h(n);
83
- const g = !!(t || f?.isEmpty);
84
- S(() => a == null || g ? void 0 : a.subscribe(
83
+ const m = !!(t || f?.isDisabled);
84
+ D(() => a == null || m ? void 0 : a.subscribe(
85
85
  c,
86
86
  p,
87
87
  (v) => {
88
88
  if ((v?.length || 0) === 0) return;
89
89
  let i;
90
- if (typeof o == "function" ? i = v.filter((m) => !o(m)) : i = v, i.length === 0 || typeof c?.notify != "function")
90
+ if (typeof o == "function" ? i = v.filter((d) => !o(d)) : i = v, i.length === 0 || typeof c?.notify != "function")
91
91
  return;
92
92
  const x = c.notify();
93
- typeof s == "function" && x.then((m) => s(m, i));
93
+ typeof s == "function" && x.then((d) => s(d, i));
94
94
  }
95
- ), [a, g, c, p, o, s]);
95
+ ), [a, m, c, p, o, s]);
96
96
  }
97
97
  function T({
98
98
  eventReceiver: r,
@@ -110,7 +110,7 @@ function T({
110
110
  options: n,
111
111
  onEvent: o,
112
112
  onNotify: s
113
- }), /* @__PURE__ */ C(w, { children: u });
113
+ }), /* @__PURE__ */ E(S, { children: u });
114
114
  }
115
115
  export {
116
116
  J as ConfigConsumer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@civet/events",
3
- "version": "2.0.3",
3
+ "version": "3.0.0",
4
4
  "description": "Civet",
5
5
  "author": {
6
6
  "name": "Aaron Burmeister"
@@ -50,12 +50,12 @@
50
50
  "uuid": "^13.0.0"
51
51
  },
52
52
  "peerDependencies": {
53
- "@civet/core": ">=2.0",
53
+ "@civet/core": ">=6.0",
54
54
  "react": ">=18.0",
55
55
  "react-dom": ">=18.0"
56
56
  },
57
57
  "devDependencies": {
58
- "@civet/core": "^2.1.3",
58
+ "@civet/core": "^6.0.2",
59
59
  "@eslint/js": "^9.35.0",
60
60
  "@types/react": "^19.1.12",
61
61
  "@types/react-dom": "^19.1.9",
@@ -66,17 +66,17 @@
66
66
  "eslint-import-resolver-typescript": "^4.4.4",
67
67
  "eslint-plugin-import": "^2.32.0",
68
68
  "eslint-plugin-prettier": "^5.5.4",
69
- "eslint-plugin-react-hooks": "^5.2.0",
70
- "eslint-plugin-react-refresh": "^0.4.20",
69
+ "eslint-plugin-react-hooks": "^7.0.1",
70
+ "eslint-plugin-react-refresh": "^0.5.0",
71
71
  "eslint-plugin-unused-imports": "^4.2.0",
72
- "globals": "^16.4.0",
72
+ "globals": "^17.3.0",
73
73
  "prettier": "^3.6.2",
74
74
  "react": "^19.1.1",
75
75
  "react-dom": "^19.1.1",
76
76
  "typescript": "^5.9.2",
77
- "typescript-eslint": "^8.43.0",
77
+ "typescript-eslint": "^8.56.0",
78
78
  "vite": "^7.1.5",
79
79
  "vite-plugin-dts": "^4.5.4",
80
- "vite-tsconfig-paths": "^5.1.4"
80
+ "vite-tsconfig-paths": "^6.1.1"
81
81
  }
82
82
  }