@civet/events 4.0.1 → 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.
@@ -3,7 +3,7 @@ export default abstract class EventReceiver<Event, Resource extends ResourceCont
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]> | 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 P, useContext as N, useMemo as A, useState as y, useEffect as h } from "react";
2
- import { jsx as x, Fragment as M } from "react/jsx-runtime";
3
- import { Notifier as j, useResourceContext as B, createPlugin as I } from "@civet/core";
4
- const l = P({});
5
- l.displayName = "Events.ConfigContext";
6
- const V = l.Consumer, k = () => N(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,12 @@ 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 = e != null;
21
- n || (e = new j());
22
- const s = this.handleSubscribe(
23
- e,
20
+ const n = e instanceof l ? e : new l(), s = this.handleSubscribe(
21
+ n,
24
22
  t,
25
23
  r
26
24
  );
27
- return n || e?.trigger(void 0), typeof s != "function" && console.warn(
25
+ return e instanceof l || n.trigger(e), typeof s != "function" && console.warn(
28
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."
29
27
  ), s;
30
28
  }
@@ -35,14 +33,14 @@ function Y({
35
33
  children: e
36
34
  }) {
37
35
  const t = A(() => ({ eventReceiver: o }), [o]);
38
- return /* @__PURE__ */ x(l.Provider, { value: t, children: e });
36
+ return /* @__PURE__ */ j(a.Provider, { value: t, children: e });
39
37
  }
40
38
  function G(o) {
41
39
  return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
42
40
  }
43
- var E, q;
41
+ var C, x;
44
42
  function J() {
45
- return q || (q = 1, E = function o(e, t) {
43
+ return x || (x = 1, C = function o(e, t) {
46
44
  if (e === t) return !0;
47
45
  if (e && t && typeof e == "object" && typeof t == "object") {
48
46
  if (e.constructor !== t.constructor) return !1;
@@ -66,7 +64,7 @@ function J() {
66
64
  return !0;
67
65
  }
68
66
  return e !== e && t !== t;
69
- }), E;
67
+ }), C;
70
68
  }
71
69
  var K = J();
72
70
  const L = /* @__PURE__ */ G(K);
@@ -78,45 +76,45 @@ function w({
78
76
  onEvent: n,
79
77
  onNotify: s
80
78
  }) {
81
- const c = k(), a = o || c.eventReceiver, D = B(), u = e === null ? void 0 : e || D, [i, S] = y(
79
+ const c = k(), p = o || c.eventReceiver, D = B(), u = e === null ? void 0 : e || D, [i, S] = E(
82
80
  u
83
81
  );
84
82
  u?.request !== i?.request && S(u);
85
- const [p, _] = y(r);
86
- L(p, r) || _(r);
87
- const C = !!(t || u?.isDisabled), [
88
- [R, b, v] = [],
89
- O
90
- ] = y();
83
+ const [v, _] = E(r);
84
+ L(v, r) || _(r);
85
+ const R = !!(t || u?.isDisabled), [
86
+ [b, O, d] = [],
87
+ q
88
+ ] = E();
91
89
  h(() => {
92
- if (a == null || C) {
93
- O(void 0);
90
+ if (p == null || R) {
91
+ q(void 0);
94
92
  return;
95
93
  }
96
- const d = new j(), F = a.subscribe(
97
- d,
98
- p,
99
- (g) => {
100
- 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;
101
99
  let f;
102
- 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")
103
101
  return;
104
102
  const H = i.notify();
105
- typeof s == "function" && H.then((m) => s(m, f));
103
+ typeof s == "function" && H.then((y) => s(y, f));
106
104
  }
107
105
  );
108
- return d.trigger(i), O([
106
+ return g.trigger(i), q([
109
107
  i?.request,
110
108
  i?.revision,
111
- d
109
+ g
112
110
  ]), F;
113
- }, [a, C, i, p, n, s]), h(() => {
114
- v == null || u?.request !== R || u?.revision === b || v.trigger(u);
111
+ }, [p, R, i, v, n, s]), h(() => {
112
+ d == null || u?.request !== b || u?.revision === O || d.trigger(u);
115
113
  }, [
116
- v,
114
+ d,
117
115
  u,
118
- R,
119
- b
116
+ b,
117
+ O
120
118
  ]);
121
119
  }
122
120
  function Z({
@@ -135,7 +133,7 @@ function Z({
135
133
  options: r,
136
134
  onEvent: n,
137
135
  onNotify: s
138
- }), /* @__PURE__ */ x(M, { children: c });
136
+ }), /* @__PURE__ */ j(M, { children: c });
139
137
  }
140
138
  const $ = I(
141
139
  (o) => class extends o {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@civet/events",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "description": "Civet",
5
5
  "author": {
6
6
  "name": "Aaron Burmeister"