elbe-ui 1.0.4 → 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.
@@ -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) => _worker(() => bitP.worker(p), 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;
@@ -113,6 +131,9 @@ export function _makeBitProvider(context, bitP) {
113
131
  useEffect(() => {
114
132
  ctrl.reload(true);
115
133
  return () => {
134
+ if (streamCancel)
135
+ streamCancel();
136
+ // call dispose if exists
116
137
  const d = ctrl.dispose;
117
138
  if (typeof d !== "function")
118
139
  return;
@@ -123,7 +144,7 @@ export function _makeBitProvider(context, bitP) {
123
144
  // ignore errors during dispose
124
145
  }
125
146
  };
126
- }, [ctrl]);
147
+ }, []);
127
148
  // ========== DEFINE THE JSX ELEMENT ==========
128
149
  return _jsx(context.Provider, { value: ctrl, children: p.children });
129
150
  }
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
- worker: (params: P) => PromiseOr<D>;
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>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elbe-ui",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "author": "Robin Naumann",
5
5
  "license": "MIT",
6
6
  "repository": {