@civet/events 4.0.0 → 4.1.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,9 +1,9 @@
1
- import { Constructor, GenericDataProvider, Notifier, ResourceContextValue } from '@civet/core';
1
+ import { Notifier, Constructor, GenericDataProvider, ResourceContextValue } from '@civet/core';
2
2
  export default abstract class EventReceiver<Event, Resource extends ResourceContextValue<GenericDataProvider>, Options> {
3
3
  readonly _inferEvent: Event;
4
4
  readonly _inferResource: Resource;
5
5
  readonly _inferOptions: Options;
6
- subscribe<EventI extends Event = Event, ResourceI extends Resource = Resource, OptionsI extends Options = Options>(resource: Notifier<[ResourceI | undefined]>, options: OptionsI | undefined, handler: (events: EventI[]) => void): () => void;
6
+ subscribe<EventI extends Event = Event, ResourceI extends Resource = Resource, OptionsI extends Options = Options>(resource: ResourceI | Notifier<[ResourceI | undefined]> | undefined, options: OptionsI | undefined, handler: (events: EventI[]) => void): () => void;
7
7
  abstract handleSubscribe(resource: Notifier<[Resource | undefined]>, options: Options | undefined, handler: (events: Event[]) => void): () => void;
8
8
  }
9
9
  export declare const isEventReceiver: (eventReceiver: unknown) => boolean;
package/dist/main.js CHANGED
@@ -1,9 +1,9 @@
1
- import { createContext as H, useContext as P, useMemo as N, useState as y, useEffect as q } from "react";
2
- import { jsx as x, Fragment as A } from "react/jsx-runtime";
3
- import { useResourceContext as M, Notifier as B, createPlugin as I } from "@civet/core";
4
- const l = H({});
5
- l.displayName = "Events.ConfigContext";
6
- const V = l.Consumer, k = () => P(l);
1
+ import { createContext as N, useContext as P, useMemo as A, useState as E, useEffect as h } from "react";
2
+ import { jsx as j, Fragment as M } from "react/jsx-runtime";
3
+ import { Notifier as l, useResourceContext as B, createPlugin as I } from "@civet/core";
4
+ const a = N({});
5
+ a.displayName = "Events.ConfigContext";
6
+ const V = a.Consumer, k = () => P(a);
7
7
  function W(...o) {
8
8
  return (...e) => o.reduce(
9
9
  (t, r) => t || (typeof r == "function" ? r(...e) : !1),
@@ -17,14 +17,14 @@ class z {
17
17
  subscribe(e, t, r) {
18
18
  if (typeof r != "function")
19
19
  throw new Error("Handler must be a function");
20
- const n = this.handleSubscribe(
21
- e,
20
+ const n = e instanceof l ? e : new l(), s = this.handleSubscribe(
21
+ n,
22
22
  t,
23
23
  r
24
24
  );
25
- return typeof n != "function" && console.warn(
25
+ return e instanceof l || n.trigger(e), typeof s != "function" && console.warn(
26
26
  "EventReceiver.handleSubscribe should return a callback to cancel the subscription. Ignoring this warning may result in the execution of obsolete handlers and potential memory leaks."
27
- ), n;
27
+ ), s;
28
28
  }
29
29
  }
30
30
  const X = (o) => o instanceof z;
@@ -32,15 +32,15 @@ function Y({
32
32
  eventReceiver: o,
33
33
  children: e
34
34
  }) {
35
- const t = N(() => ({ eventReceiver: o }), [o]);
36
- return /* @__PURE__ */ x(l.Provider, { value: t, children: e });
35
+ const t = A(() => ({ eventReceiver: o }), [o]);
36
+ return /* @__PURE__ */ j(a.Provider, { value: t, children: e });
37
37
  }
38
38
  function G(o) {
39
39
  return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
40
40
  }
41
- var E, h;
41
+ var C, x;
42
42
  function J() {
43
- return h || (h = 1, E = function o(e, t) {
43
+ return x || (x = 1, C = function o(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,11 +64,11 @@ function J() {
64
64
  return !0;
65
65
  }
66
66
  return e !== e && t !== t;
67
- }), E;
67
+ }), C;
68
68
  }
69
69
  var K = J();
70
70
  const L = /* @__PURE__ */ G(K);
71
- function j({
71
+ function w({
72
72
  eventReceiver: o,
73
73
  resource: e,
74
74
  disabled: t,
@@ -76,45 +76,45 @@ function j({
76
76
  onEvent: n,
77
77
  onNotify: s
78
78
  }) {
79
- const c = k(), a = o || c.eventReceiver, D = M(), u = e === null ? void 0 : e || D, [i, w] = y(
79
+ const c = k(), p = o || c.eventReceiver, D = B(), u = e === null ? void 0 : e || D, [i, S] = E(
80
80
  u
81
81
  );
82
- u?.request !== i?.request && w(u);
83
- const [p, S] = y(r);
84
- L(p, r) || S(r);
85
- const C = !!(t || u?.isDisabled), [
86
- [R, b, v] = [],
87
- O
88
- ] = y();
89
- q(() => {
90
- if (a == null || C) {
91
- O(void 0);
82
+ u?.request !== i?.request && S(u);
83
+ const [v, _] = E(r);
84
+ L(v, r) || _(r);
85
+ const R = !!(t || u?.isDisabled), [
86
+ [b, O, d] = [],
87
+ q
88
+ ] = E();
89
+ h(() => {
90
+ if (p == null || R) {
91
+ q(void 0);
92
92
  return;
93
93
  }
94
- const d = new B(), _ = a.subscribe(
95
- d,
96
- p,
97
- (g) => {
98
- if ((g?.length || 0) === 0) return;
94
+ const g = new l(), F = p.subscribe(
95
+ g,
96
+ v,
97
+ (m) => {
98
+ if ((m?.length || 0) === 0) return;
99
99
  let f;
100
- if (typeof n == "function" ? f = g.filter((m) => !n(m)) : f = g, f.length === 0 || typeof i?.notify != "function")
100
+ if (typeof n == "function" ? f = m.filter((y) => !n(y)) : f = m, f.length === 0 || typeof i?.notify != "function")
101
101
  return;
102
- const F = i.notify();
103
- typeof s == "function" && F.then((m) => s(m, f));
102
+ const H = i.notify();
103
+ typeof s == "function" && H.then((y) => s(y, f));
104
104
  }
105
105
  );
106
- return d.trigger(i), O([
106
+ return g.trigger(i), q([
107
107
  i?.request,
108
108
  i?.revision,
109
- d
110
- ]), _;
111
- }, [a, C, i, p, n, s]), q(() => {
112
- v == null || u?.request !== R || u?.revision === b || v.trigger(u);
109
+ g
110
+ ]), F;
111
+ }, [p, R, i, v, n, s]), h(() => {
112
+ d == null || u?.request !== b || u?.revision === O || d.trigger(u);
113
113
  }, [
114
- v,
114
+ d,
115
115
  u,
116
- R,
117
- b
116
+ b,
117
+ O
118
118
  ]);
119
119
  }
120
120
  function Z({
@@ -126,20 +126,20 @@ function Z({
126
126
  onNotify: s,
127
127
  children: c
128
128
  }) {
129
- return j({
129
+ return w({
130
130
  eventReceiver: o,
131
131
  resource: e,
132
132
  disabled: t,
133
133
  options: r,
134
134
  onEvent: n,
135
135
  onNotify: s
136
- }), /* @__PURE__ */ x(A, { children: c });
136
+ }), /* @__PURE__ */ j(M, { children: c });
137
137
  }
138
138
  const $ = I(
139
139
  (o) => class extends o {
140
140
  extend(t) {
141
141
  t.context(
142
- (r, { events: n = !1 }) => (j(
142
+ (r, { events: n = !1 }) => (w(
143
143
  typeof n == "boolean" ? { disabled: !n, resource: r } : { ...n, resource: r }
144
144
  ), r)
145
145
  );
@@ -155,5 +155,5 @@ export {
155
155
  $ as eventPlugin,
156
156
  X as isEventReceiver,
157
157
  k as useConfigContext,
158
- j as useEventHandler
158
+ w as useEventHandler
159
159
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@civet/events",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "Civet",
5
5
  "author": {
6
6
  "name": "Aaron Burmeister"