elbe-ui 1.0.3 → 1.0.5
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/bit/_bit_provider.js +33 -1
- package/dist/bit/bit.d.ts +12 -3
- package/package.json +1 -1
|
@@ -16,6 +16,7 @@ function _LoadView({}) {
|
|
|
16
16
|
}
|
|
17
17
|
export function _makeBitProvider(context, bitP) {
|
|
18
18
|
function _BitProvider(p) {
|
|
19
|
+
const [streamCancel, setStreamCancel] = useState(null);
|
|
19
20
|
const [state, setState] = useState({
|
|
20
21
|
v: { type: "loading" },
|
|
21
22
|
history: [],
|
|
@@ -74,7 +75,24 @@ export function _makeBitProvider(context, bitP) {
|
|
|
74
75
|
}
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
|
-
const _reload = (silent) =>
|
|
78
|
+
const _reload = (silent) => {
|
|
79
|
+
const _bit = bitP;
|
|
80
|
+
if (_bit.stream) {
|
|
81
|
+
try {
|
|
82
|
+
if (!silent)
|
|
83
|
+
_partCtrl.setLoading();
|
|
84
|
+
if (streamCancel)
|
|
85
|
+
streamCancel();
|
|
86
|
+
const cancel = _bit.stream(p, _partCtrl);
|
|
87
|
+
setStreamCancel(() => cancel);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
_partCtrl.setError(e);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
_worker(() => _bit.worker(p), silent);
|
|
95
|
+
};
|
|
78
96
|
function act(fn, silent) {
|
|
79
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80
98
|
const data = _partCtrl.data;
|
|
@@ -112,6 +130,20 @@ export function _makeBitProvider(context, bitP) {
|
|
|
112
130
|
const ctrl = useMemo(() => _make(), [state]);
|
|
113
131
|
useEffect(() => {
|
|
114
132
|
ctrl.reload(true);
|
|
133
|
+
return () => {
|
|
134
|
+
if (streamCancel)
|
|
135
|
+
streamCancel();
|
|
136
|
+
// call dispose if exists
|
|
137
|
+
const d = ctrl.dispose;
|
|
138
|
+
if (typeof d !== "function")
|
|
139
|
+
return;
|
|
140
|
+
try {
|
|
141
|
+
d();
|
|
142
|
+
}
|
|
143
|
+
catch (_a) {
|
|
144
|
+
// ignore errors during dispose
|
|
145
|
+
}
|
|
146
|
+
};
|
|
115
147
|
}, []);
|
|
116
148
|
// ========== DEFINE THE JSX ELEMENT ==========
|
|
117
149
|
return _jsx(context.Provider, { value: ctrl, children: p.children });
|
package/dist/bit/bit.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Context } from "react";
|
|
2
2
|
import { Maybe, PromiseOr } from "..";
|
|
3
|
-
import { _BitCtrlMaker, _BitData, _BitGetInterface, _BitInterface } from "./_bit_utils";
|
|
3
|
+
import { _BitCtrlInput, _BitCtrlMaker, _BitData, _BitGetInterface, _BitInterface } from "./_bit_utils";
|
|
4
4
|
export type BitStates = "loading" | "error" | "data";
|
|
5
5
|
export type BitContext<D> = Context<_BitData<D> | null>;
|
|
6
6
|
export type BitTriMap<T, D> = {
|
|
@@ -14,7 +14,16 @@ export type BitUseInterface<D, P, I> = _BitGetInterface<D> & I & {
|
|
|
14
14
|
export type BitParams<D, P, I> = {
|
|
15
15
|
control?: _BitCtrlMaker<D, P, I>;
|
|
16
16
|
debugLabel?: Maybe<string>;
|
|
17
|
-
|
|
17
|
+
/** the value will not be used allows Typescript to infer the data type.
|
|
18
|
+
*
|
|
19
|
+
* So, pass a value like this:
|
|
20
|
+
* `dataTypeHint: null as any as {[key: string]: number}`
|
|
21
|
+
*/
|
|
22
|
+
dataTypeHint?: D;
|
|
18
23
|
useHistory?: boolean;
|
|
19
|
-
}
|
|
24
|
+
} & ({
|
|
25
|
+
worker: (params: P) => PromiseOr<D>;
|
|
26
|
+
} | {
|
|
27
|
+
stream: (params: P, ctrl: _BitCtrlInput<D, P>) => () => void;
|
|
28
|
+
});
|
|
20
29
|
export declare function createBit<D, P extends Object, I>({ control, ...p }: BitParams<D, P, I>): _BitInterface<D, P, I>;
|