@civet/events 4.0.0 → 4.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,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: 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({});
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
5
  l.displayName = "Events.ConfigContext";
6
- const V = l.Consumer, k = () => P(l);
6
+ const V = l.Consumer, k = () => N(l);
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,16 @@ 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(
20
+ const n = e != null;
21
+ n || (e = new j());
22
+ const s = this.handleSubscribe(
21
23
  e,
22
24
  t,
23
25
  r
24
26
  );
25
- return typeof n != "function" && console.warn(
27
+ return n || e?.trigger(void 0), typeof s != "function" && console.warn(
26
28
  "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;
29
+ ), s;
28
30
  }
29
31
  }
30
32
  const X = (o) => o instanceof z;
@@ -32,15 +34,15 @@ function Y({
32
34
  eventReceiver: o,
33
35
  children: e
34
36
  }) {
35
- const t = N(() => ({ eventReceiver: o }), [o]);
37
+ const t = A(() => ({ eventReceiver: o }), [o]);
36
38
  return /* @__PURE__ */ x(l.Provider, { value: t, children: e });
37
39
  }
38
40
  function G(o) {
39
41
  return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
40
42
  }
41
- var E, h;
43
+ var E, q;
42
44
  function J() {
43
- return h || (h = 1, E = function o(e, t) {
45
+ return q || (q = 1, E = function o(e, t) {
44
46
  if (e === t) return !0;
45
47
  if (e && t && typeof e == "object" && typeof t == "object") {
46
48
  if (e.constructor !== t.constructor) return !1;
@@ -68,7 +70,7 @@ function J() {
68
70
  }
69
71
  var K = J();
70
72
  const L = /* @__PURE__ */ G(K);
71
- function j({
73
+ function w({
72
74
  eventReceiver: o,
73
75
  resource: e,
74
76
  disabled: t,
@@ -76,22 +78,22 @@ function j({
76
78
  onEvent: n,
77
79
  onNotify: s
78
80
  }) {
79
- const c = k(), a = o || c.eventReceiver, D = M(), u = e === null ? void 0 : e || D, [i, w] = y(
81
+ const c = k(), a = o || c.eventReceiver, D = B(), u = e === null ? void 0 : e || D, [i, S] = y(
80
82
  u
81
83
  );
82
- u?.request !== i?.request && w(u);
83
- const [p, S] = y(r);
84
- L(p, r) || S(r);
84
+ u?.request !== i?.request && S(u);
85
+ const [p, _] = y(r);
86
+ L(p, r) || _(r);
85
87
  const C = !!(t || u?.isDisabled), [
86
88
  [R, b, v] = [],
87
89
  O
88
90
  ] = y();
89
- q(() => {
91
+ h(() => {
90
92
  if (a == null || C) {
91
93
  O(void 0);
92
94
  return;
93
95
  }
94
- const d = new B(), _ = a.subscribe(
96
+ const d = new j(), F = a.subscribe(
95
97
  d,
96
98
  p,
97
99
  (g) => {
@@ -99,16 +101,16 @@ function j({
99
101
  let f;
100
102
  if (typeof n == "function" ? f = g.filter((m) => !n(m)) : f = g, f.length === 0 || typeof i?.notify != "function")
101
103
  return;
102
- const F = i.notify();
103
- typeof s == "function" && F.then((m) => s(m, f));
104
+ const H = i.notify();
105
+ typeof s == "function" && H.then((m) => s(m, f));
104
106
  }
105
107
  );
106
108
  return d.trigger(i), O([
107
109
  i?.request,
108
110
  i?.revision,
109
111
  d
110
- ]), _;
111
- }, [a, C, i, p, n, s]), q(() => {
112
+ ]), F;
113
+ }, [a, C, i, p, n, s]), h(() => {
112
114
  v == null || u?.request !== R || u?.revision === b || v.trigger(u);
113
115
  }, [
114
116
  v,
@@ -126,20 +128,20 @@ function Z({
126
128
  onNotify: s,
127
129
  children: c
128
130
  }) {
129
- return j({
131
+ return w({
130
132
  eventReceiver: o,
131
133
  resource: e,
132
134
  disabled: t,
133
135
  options: r,
134
136
  onEvent: n,
135
137
  onNotify: s
136
- }), /* @__PURE__ */ x(A, { children: c });
138
+ }), /* @__PURE__ */ x(M, { children: c });
137
139
  }
138
140
  const $ = I(
139
141
  (o) => class extends o {
140
142
  extend(t) {
141
143
  t.context(
142
- (r, { events: n = !1 }) => (j(
144
+ (r, { events: n = !1 }) => (w(
143
145
  typeof n == "boolean" ? { disabled: !n, resource: r } : { ...n, resource: r }
144
146
  ), r)
145
147
  );
@@ -155,5 +157,5 @@ export {
155
157
  $ as eventPlugin,
156
158
  X as isEventReceiver,
157
159
  k as useConfigContext,
158
- j as useEventHandler
160
+ w as useEventHandler
159
161
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@civet/events",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Civet",
5
5
  "author": {
6
6
  "name": "Aaron Burmeister"