elbe-ui 1.0.4 → 1.0.6

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,25 @@ 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
+ console.error("[BIT] Error in stream preparation:", e);
92
+ _partCtrl.setError(e);
93
+ }
94
+ }
95
+ _worker(() => _bit.worker(p), silent);
96
+ };
78
97
  function act(fn, silent) {
79
98
  return __awaiter(this, void 0, void 0, function* () {
80
99
  const data = _partCtrl.data;
@@ -113,6 +132,9 @@ export function _makeBitProvider(context, bitP) {
113
132
  useEffect(() => {
114
133
  ctrl.reload(true);
115
134
  return () => {
135
+ if (streamCancel)
136
+ streamCancel();
137
+ // call dispose if exists
116
138
  const d = ctrl.dispose;
117
139
  if (typeof d !== "function")
118
140
  return;
@@ -123,7 +145,7 @@ export function _makeBitProvider(context, bitP) {
123
145
  // ignore errors during dispose
124
146
  }
125
147
  };
126
- }, [ctrl]);
148
+ }, []);
127
149
  // ========== DEFINE THE JSX ELEMENT ==========
128
150
  return _jsx(context.Provider, { value: ctrl, children: p.children });
129
151
  }
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>;
@@ -50,7 +50,7 @@ export function Menu(p) {
50
50
  : {})), children: wideOrOpen() && (_jsxs(_Fragment, { children: [_jsx(Button.plain, { contentAlign: "start", ariaLabel: "open/close menu", onTap: () => appBase.setMenuOpen(!appBase.menuOpen), icon: MenuIcon, style: {
51
51
  marginBottom: ".5rem",
52
52
  borderRadius: "3rem",
53
- }, children: !layoutMode.isWide && (_jsx(_Logo, { logo: appBase === null || appBase === void 0 ? void 0 : appBase.icons.logo, logoDark: appBase === null || appBase === void 0 ? void 0 : appBase.icons.logoDark, lMargin: 0.5 })) }), _jsx(Column, { flex: 1, scroll: true, noScrollbar: true, children: topBot.top.map((i) => (_jsx(_MenuItemView, { item: i }))) }), topBot.bottom.map((i) => (_jsx(_MenuItemView, { item: i })))] })) })] }));
53
+ }, children: !layoutMode.isWide && (_jsx(_Logo, { logo: appBase === null || appBase === void 0 ? void 0 : appBase.icons.logo, logoDark: appBase === null || appBase === void 0 ? void 0 : appBase.icons.logoDark, lMargin: 0.5 })) }), _jsx(Column, { flex: 1, scroll: true, noScrollbar: true, children: topBot.top.map((i, index) => (_jsx(_MenuItemView, { item: i }, index))) }), topBot.bottom.map((i, index) => (_jsx(_MenuItemView, { item: i }, index)))] })) })] }));
54
54
  }
55
55
  function _MenuItemView({ item }) {
56
56
  const appBase = useAppBase();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elbe-ui",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "author": "Robin Naumann",
5
5
  "license": "MIT",
6
6
  "repository": {