elbe-ui 0.4.8 → 0.4.9
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 +11 -6
- package/dist/bit/_bit_utils.d.ts +5 -0
- package/dist/bit/bit.d.ts +1 -3
- package/package.json +1 -1
|
@@ -56,20 +56,25 @@ export function _makeBitProvider(context, bitP) {
|
|
|
56
56
|
error: state.v.type === "error" ? state.v.value : undefined,
|
|
57
57
|
};
|
|
58
58
|
// ========== DEFINE QoL FUNCTIONS ==========
|
|
59
|
-
function _worker(fn, silent) {
|
|
59
|
+
function _worker(fn, silent, reset) {
|
|
60
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
61
|
if (!silent)
|
|
62
62
|
_partCtrl.setLoading();
|
|
63
63
|
try {
|
|
64
64
|
const newData = yield fn();
|
|
65
|
-
|
|
65
|
+
if (!reset)
|
|
66
|
+
return _partCtrl.setData(newData);
|
|
67
|
+
setState({
|
|
68
|
+
history: bitP.useHistory ? [newData] : [],
|
|
69
|
+
v: { type: "data", value: newData },
|
|
70
|
+
});
|
|
66
71
|
}
|
|
67
72
|
catch (e) {
|
|
68
73
|
_partCtrl.setError(e);
|
|
69
74
|
}
|
|
70
75
|
});
|
|
71
76
|
}
|
|
72
|
-
const _reload = () => _worker(() => bitP.worker(p));
|
|
77
|
+
const _reload = (silent) => _worker(() => bitP.worker(p), silent);
|
|
73
78
|
function act(fn, silent) {
|
|
74
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
80
|
const data = _partCtrl.data;
|
|
@@ -93,16 +98,16 @@ export function _makeBitProvider(context, bitP) {
|
|
|
93
98
|
return _isFn(onLoading) ? onLoading() : (_c = onLoading) !== null && _c !== void 0 ? _c : null;
|
|
94
99
|
}
|
|
95
100
|
function mapUI(onData, onError, onLoading) {
|
|
96
|
-
return map((d) => onData(d), (e) => (onError !== null && onError !== void 0 ? onError : ((e) => _jsx(ErrorView, { error: e, retry: _reload })))(e), () => onLoading !== null && onLoading !== void 0 ? onLoading : (() => _jsx(_LoadView, {}))());
|
|
101
|
+
return map((d) => onData(d), (e) => (onError !== null && onError !== void 0 ? onError : ((e) => _jsx(ErrorView, { error: e, retry: () => _reload(false) })))(e), () => onLoading !== null && onLoading !== void 0 ? onLoading : (() => _jsx(_LoadView, {}))());
|
|
97
102
|
}
|
|
98
103
|
const baseCtrl = Object.assign(Object.assign({}, _partCtrl), { act,
|
|
99
104
|
map,
|
|
100
105
|
mapUI });
|
|
101
|
-
const userCtrl = bitP.control(Object.assign(Object.assign({}, baseCtrl), { parameters: p }));
|
|
106
|
+
const userCtrl = bitP.control(Object.assign(Object.assign({}, baseCtrl), { parameters: p, reload: _reload }));
|
|
102
107
|
return Object.assign(Object.assign(Object.assign({}, baseCtrl), userCtrl), { reload: _reload });
|
|
103
108
|
}
|
|
104
109
|
const ctrl = useMemo(() => _make(), [state]);
|
|
105
|
-
useEffect(() => ctrl.reload(), []);
|
|
110
|
+
useEffect(() => ctrl.reload(true), []);
|
|
106
111
|
// ========== DEFINE THE JSX ELEMENT ==========
|
|
107
112
|
return _jsx(context.Provider, { value: ctrl, children: p.children });
|
|
108
113
|
}
|
package/dist/bit/_bit_utils.d.ts
CHANGED
|
@@ -73,6 +73,11 @@ export interface _BitGetInterface<D> {
|
|
|
73
73
|
* returns true if a previous `data` state exists.
|
|
74
74
|
*/
|
|
75
75
|
canGoBack: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* reload the data. It will call the worker function again.
|
|
78
|
+
* If `silent` is true, it will not change the state to `loading`.
|
|
79
|
+
*/
|
|
80
|
+
reload: (silent?: boolean) => void;
|
|
76
81
|
}
|
|
77
82
|
export interface _BitCtrlInput<D, P> extends _BitGetInterface<D> {
|
|
78
83
|
setData: (d: D) => void;
|
package/dist/bit/bit.d.ts
CHANGED
|
@@ -8,9 +8,7 @@ export type BitTriMap<T, D> = {
|
|
|
8
8
|
onError?: (e: any) => D;
|
|
9
9
|
onData?: (value: T) => D;
|
|
10
10
|
};
|
|
11
|
-
export type BitUseInterface<D, I> = _BitGetInterface<D> & I
|
|
12
|
-
reload: () => void;
|
|
13
|
-
};
|
|
11
|
+
export type BitUseInterface<D, I> = _BitGetInterface<D> & I;
|
|
14
12
|
export type BitParams<D, P, I> = {
|
|
15
13
|
control?: _BitCtrlMaker<D, P, I>;
|
|
16
14
|
debugLabel?: Maybe<string>;
|