@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.
- package/dist/EventReceiver.d.ts +2 -2
- package/dist/main.js +47 -47
- package/package.json +1 -1
package/dist/EventReceiver.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Constructor, GenericDataProvider,
|
|
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]
|
|
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 {
|
|
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,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
|
-
|
|
20
|
+
const n = e instanceof l ? e : new l(), s = this.handleSubscribe(
|
|
21
|
+
n,
|
|
22
22
|
t,
|
|
23
23
|
r
|
|
24
24
|
);
|
|
25
|
-
return
|
|
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
|
-
),
|
|
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 =
|
|
36
|
-
return /* @__PURE__ */
|
|
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
|
|
41
|
+
var C, x;
|
|
42
42
|
function J() {
|
|
43
|
-
return
|
|
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
|
-
}),
|
|
67
|
+
}), C;
|
|
68
68
|
}
|
|
69
69
|
var K = J();
|
|
70
70
|
const L = /* @__PURE__ */ G(K);
|
|
71
|
-
function
|
|
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(),
|
|
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 &&
|
|
83
|
-
const [
|
|
84
|
-
L(
|
|
85
|
-
const
|
|
86
|
-
[
|
|
87
|
-
|
|
88
|
-
] =
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
|
|
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
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
(
|
|
98
|
-
if ((
|
|
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 =
|
|
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
|
|
103
|
-
typeof s == "function" &&
|
|
102
|
+
const H = i.notify();
|
|
103
|
+
typeof s == "function" && H.then((y) => s(y, f));
|
|
104
104
|
}
|
|
105
105
|
);
|
|
106
|
-
return
|
|
106
|
+
return g.trigger(i), q([
|
|
107
107
|
i?.request,
|
|
108
108
|
i?.revision,
|
|
109
|
-
|
|
110
|
-
]),
|
|
111
|
-
}, [
|
|
112
|
-
|
|
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
|
-
|
|
114
|
+
d,
|
|
115
115
|
u,
|
|
116
|
-
|
|
117
|
-
|
|
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
|
|
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__ */
|
|
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 }) => (
|
|
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
|
-
|
|
158
|
+
w as useEventHandler
|
|
159
159
|
};
|