@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.
- package/dist/EventReceiver.d.ts +1 -1
- package/dist/main.js +37 -39
- package/package.json +1 -1
package/dist/EventReceiver.d.ts
CHANGED
|
@@ -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
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { Notifier as
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const V =
|
|
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
|
|
21
|
-
|
|
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
|
|
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__ */
|
|
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
|
|
41
|
+
var C, x;
|
|
44
42
|
function J() {
|
|
45
|
-
return
|
|
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
|
-
}),
|
|
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(),
|
|
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 [
|
|
86
|
-
L(
|
|
87
|
-
const
|
|
88
|
-
[
|
|
89
|
-
|
|
90
|
-
] =
|
|
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 (
|
|
93
|
-
|
|
90
|
+
if (p == null || R) {
|
|
91
|
+
q(void 0);
|
|
94
92
|
return;
|
|
95
93
|
}
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
(
|
|
100
|
-
if ((
|
|
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 =
|
|
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((
|
|
103
|
+
typeof s == "function" && H.then((y) => s(y, f));
|
|
106
104
|
}
|
|
107
105
|
);
|
|
108
|
-
return
|
|
106
|
+
return g.trigger(i), q([
|
|
109
107
|
i?.request,
|
|
110
108
|
i?.revision,
|
|
111
|
-
|
|
109
|
+
g
|
|
112
110
|
]), F;
|
|
113
|
-
}, [
|
|
114
|
-
|
|
111
|
+
}, [p, R, i, v, n, s]), h(() => {
|
|
112
|
+
d == null || u?.request !== b || u?.revision === O || d.trigger(u);
|
|
115
113
|
}, [
|
|
116
|
-
|
|
114
|
+
d,
|
|
117
115
|
u,
|
|
118
|
-
|
|
119
|
-
|
|
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__ */
|
|
136
|
+
}), /* @__PURE__ */ j(M, { children: c });
|
|
139
137
|
}
|
|
140
138
|
const $ = I(
|
|
141
139
|
(o) => class extends o {
|