react-sync-ui 0.1.6 → 1.0.1
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/index.d.ts +6 -6
- package/dist/react-sync-ui.cjs.development.js +17 -31
- package/dist/react-sync-ui.cjs.development.js.map +1 -1
- package/dist/react-sync-ui.cjs.production.min.js +1 -1
- package/dist/react-sync-ui.cjs.production.min.js.map +1 -1
- package/dist/react-sync-ui.esm.js +17 -31
- package/dist/react-sync-ui.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/syncUI.tsx +7 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export declare const syncUIFactory: () => {
|
|
3
|
-
makeSyncUI: <
|
|
4
|
-
data:
|
|
3
|
+
makeSyncUI: <InputData, ResolveValue = void>(SyncUIUserComp: import("react").FC<{
|
|
4
|
+
data: InputData;
|
|
5
5
|
resolve: (value: ResolveValue) => void;
|
|
6
6
|
reject: (reason?: any) => void;
|
|
7
|
-
}>) => (input:
|
|
7
|
+
}>) => (input: InputData) => Promise<ResolveValue>;
|
|
8
8
|
SyncUI: () => JSX.Element;
|
|
9
9
|
};
|
|
10
|
-
export declare const makeSyncUI: <
|
|
11
|
-
data:
|
|
10
|
+
export declare const makeSyncUI: <InputData, ResolveValue = void>(SyncUIUserComp: import("react").FC<{
|
|
11
|
+
data: InputData;
|
|
12
12
|
resolve: (value: ResolveValue) => void;
|
|
13
13
|
reject: (reason?: any) => void;
|
|
14
|
-
}>) => (input:
|
|
14
|
+
}>) => (input: InputData) => Promise<ResolveValue>, SyncUI: () => JSX.Element;
|
|
@@ -10,25 +10,11 @@ var React__default = _interopDefault(React);
|
|
|
10
10
|
var useComponentDidMount = function useComponentDidMount(fn) {
|
|
11
11
|
React.useEffect(fn, []);
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
var getSingletonComponentCheck = function getSingletonComponentCheck(errorMsg) {
|
|
15
|
-
var globalMountCounter = 0;
|
|
16
|
-
return function () {
|
|
17
|
-
useComponentDidMount(function () {
|
|
18
|
-
if (globalMountCounter > 0) throw new Error(errorMsg);
|
|
19
|
-
globalMountCounter++;
|
|
20
|
-
});
|
|
21
|
-
return React__default.createElement(React__default.Fragment, null);
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
|
|
25
13
|
var usePromiseQueue = function usePromiseQueue() {
|
|
26
14
|
var _asyncQueue$;
|
|
27
|
-
|
|
28
15
|
var _useState = React.useState([]),
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
16
|
+
asyncQueue = _useState[0],
|
|
17
|
+
setAsyncQueue = _useState[1];
|
|
32
18
|
var push = React.useCallback(function (data) {
|
|
33
19
|
return new Promise(function (resolve, reject) {
|
|
34
20
|
return setAsyncQueue(function (p) {
|
|
@@ -43,7 +29,7 @@ var usePromiseQueue = function usePromiseQueue() {
|
|
|
43
29
|
var resolveHeadItem = React.useCallback(function (value) {
|
|
44
30
|
setAsyncQueue(function (queue) {
|
|
45
31
|
var first = queue[0],
|
|
46
|
-
|
|
32
|
+
rest = queue.slice(1);
|
|
47
33
|
first == null ? void 0 : first.resolve(value);
|
|
48
34
|
return rest;
|
|
49
35
|
});
|
|
@@ -51,7 +37,7 @@ var usePromiseQueue = function usePromiseQueue() {
|
|
|
51
37
|
var rejectHeadItem = React.useCallback(function (reason) {
|
|
52
38
|
setAsyncQueue(function (queue) {
|
|
53
39
|
var first = queue[0],
|
|
54
|
-
|
|
40
|
+
rest = queue.slice(1);
|
|
55
41
|
first == null ? void 0 : first.reject(reason);
|
|
56
42
|
return rest;
|
|
57
43
|
});
|
|
@@ -64,23 +50,25 @@ var usePromiseQueue = function usePromiseQueue() {
|
|
|
64
50
|
} : undefined,
|
|
65
51
|
push: push
|
|
66
52
|
};
|
|
67
|
-
};
|
|
68
|
-
|
|
53
|
+
};
|
|
54
|
+
// ------------------------------------------------------------------------------------
|
|
69
55
|
var syncUIFactory = function syncUIFactory() {
|
|
70
56
|
var mutSyncUIComponentsRenderQueue = [];
|
|
71
|
-
|
|
57
|
+
/*
|
|
58
|
+
// this check broke the working of the hot reloading
|
|
59
|
+
const ThrowIfMoreInstances = getSingletonComponentCheck(
|
|
60
|
+
"<SyncUI /> has to be initialized only once"
|
|
61
|
+
);
|
|
62
|
+
*/
|
|
72
63
|
return {
|
|
73
64
|
makeSyncUI: function makeSyncUI(SyncUIUserComp) {
|
|
74
65
|
var _ref, _SyncUIUserComp$displ;
|
|
75
|
-
|
|
76
66
|
var _debugName = (_ref = (_SyncUIUserComp$displ = SyncUIUserComp.displayName) != null ? _SyncUIUserComp$displ : SyncUIUserComp.name) != null ? _ref : "uniqSymbolMessageType";
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
67
|
+
var syncUIComponentType = Symbol(_debugName);
|
|
68
|
+
// object pointer reference with the push key has to be there to change returned mutable reference object while the function is already called
|
|
80
69
|
var singletonSyncUIRef = {
|
|
81
70
|
push: undefined
|
|
82
71
|
};
|
|
83
|
-
|
|
84
72
|
var SyncUISingletonComponent = function SyncUISingletonComponent(props) {
|
|
85
73
|
useComponentDidMount(function () {
|
|
86
74
|
singletonSyncUIRef.push = props.push;
|
|
@@ -96,7 +84,6 @@ var syncUIFactory = function syncUIFactory() {
|
|
|
96
84
|
reject: props.head.reject
|
|
97
85
|
});
|
|
98
86
|
};
|
|
99
|
-
|
|
100
87
|
mutSyncUIComponentsRenderQueue.push(SyncUISingletonComponent);
|
|
101
88
|
return function (input) {
|
|
102
89
|
if (!singletonSyncUIRef.push) throw new Error("You have to initialize <SyncUI />");
|
|
@@ -108,7 +95,7 @@ var syncUIFactory = function syncUIFactory() {
|
|
|
108
95
|
},
|
|
109
96
|
SyncUI: function SyncUI() {
|
|
110
97
|
var queue = usePromiseQueue();
|
|
111
|
-
return React__default.createElement(React__default.Fragment, null,
|
|
98
|
+
return React__default.createElement(React__default.Fragment, null, mutSyncUIComponentsRenderQueue.map(function (SyncComp, key) {
|
|
112
99
|
return React__default.createElement(React__default.Fragment, {
|
|
113
100
|
key: key
|
|
114
101
|
}, React__default.createElement(SyncComp, Object.assign({}, queue)));
|
|
@@ -118,10 +105,9 @@ var syncUIFactory = function syncUIFactory() {
|
|
|
118
105
|
};
|
|
119
106
|
|
|
120
107
|
var syncUIFactory$1 = syncUIFactory;
|
|
121
|
-
|
|
122
108
|
var _syncUIFactory2 = /*#__PURE__*/syncUIFactory$1(),
|
|
123
|
-
|
|
124
|
-
|
|
109
|
+
makeSyncUI = _syncUIFactory2.makeSyncUI,
|
|
110
|
+
SyncUI = _syncUIFactory2.SyncUI;
|
|
125
111
|
|
|
126
112
|
exports.SyncUI = SyncUI;
|
|
127
113
|
exports.makeSyncUI = makeSyncUI;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-sync-ui.cjs.development.js","sources":["../src/syncUI.tsx","../src/index.ts"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\n\nconst useComponentDidMount = (fn: Parameters<typeof useEffect>[0]) => {\n useEffect(fn, []);\n};\n\nconst getSingletonComponentCheck = (errorMsg: string) => {\n let globalMountCounter = 0;\n\n return () => {\n useComponentDidMount(() => {\n if (globalMountCounter > 0) throw new Error(errorMsg);\n globalMountCounter++;\n });\n return <React.Fragment />;\n };\n};\n\n// ------------------------------------------------------------------------------------\n// TODO: there is tsdx old typescript parser and new ts fancy syntax is not working...\n// https://github.com/jaredpalmer/tsdx/issues/200\n// type PromiseQueueAPI<Data, ResolveValue> = ReturnType<typeof usePromiseQueue<any, any>>\ntype PromiseQueueAPI<Data, ResolveValue> = {\n head?: {\n data: Data;\n resolve: (value: ResolveValue) => void;\n reject: (reason?: any) => void;\n };\n push: (data: Data) => Promise<ResolveValue>;\n};\n\nexport const usePromiseQueue = <Data, ResolveValue = void>(): PromiseQueueAPI<\n Data,\n ResolveValue\n> => {\n const [asyncQueue, setAsyncQueue] = useState(\n [] as {\n data: Data;\n resolve: (arg: ResolveValue) => void;\n reject: (arg: any) => void;\n }[]\n );\n\n const push = useCallback((data: Data) => {\n return new Promise<ResolveValue>((resolve, reject) =>\n setAsyncQueue(p => [...p, { data, resolve, reject }])\n );\n }, []);\n\n const resolveHeadItem = useCallback((value: ResolveValue) => {\n setAsyncQueue(queue => {\n const [first, ...rest] = queue;\n first?.resolve(value);\n return rest;\n });\n }, []);\n\n const rejectHeadItem = useCallback((reason?: any) => {\n setAsyncQueue(queue => {\n const [first, ...rest] = queue;\n first?.reject(reason);\n return rest;\n });\n }, []);\n\n return {\n head: asyncQueue[0]\n ? {\n data: asyncQueue[0]?.data,\n resolve: resolveHeadItem,\n reject: rejectHeadItem\n }\n : undefined,\n push\n };\n};\n\n// ------------------------------------------------------------------------------------\n\nexport const syncUIFactory = () => {\n const mutSyncUIComponentsRenderQueue = [] as React.FC<\n PromiseQueueAPI<any, any>\n >[];\n\n const ThrowIfMoreInstances = getSingletonComponentCheck(\n \"<SyncUI /> has to be initialized only once\"\n );\n\n return {\n makeSyncUI: <InputData, ResolveValue = void>(\n SyncUIUserComp: React.FC<{\n data: InputData;\n resolve: (value: ResolveValue) => void;\n reject: (reason?: any) => void;\n }>\n ) => {\n type QItem = PromiseQueueAPI<\n { type: Symbol; inputData: InputData },\n ResolveValue\n >;\n\n const _debugName =\n SyncUIUserComp.displayName ??\n SyncUIUserComp.name ??\n \"uniqSymbolMessageType\";\n\n const syncUIComponentType = Symbol(_debugName);\n\n // object pointer reference with the push key has to be there to change returned mutable reference object while the function is already called\n const singletonSyncUIRef = {\n push: undefined as undefined | QItem[\"push\"]\n };\n\n const SyncUISingletonComponent = (props: QItem) => {\n useComponentDidMount(() => {\n singletonSyncUIRef.push = props.push;\n return () => (singletonSyncUIRef.push = undefined);\n });\n\n if (!props.head) return null;\n if (props.head.data.type !== syncUIComponentType) return null;\n\n return (\n <SyncUIUserComp\n data={props.head.data.inputData}\n resolve={props.head.resolve}\n reject={props.head.reject}\n />\n );\n };\n\n mutSyncUIComponentsRenderQueue.push(SyncUISingletonComponent);\n\n return (input: InputData) => {\n if (!singletonSyncUIRef.push)\n throw new Error(`You have to initialize <SyncUI />`);\n return singletonSyncUIRef.push({\n type: syncUIComponentType,\n inputData: input\n });\n };\n },\n SyncUI: () => {\n const queue = usePromiseQueue();\n return (\n <>\n <ThrowIfMoreInstances
|
|
1
|
+
{"version":3,"file":"react-sync-ui.cjs.development.js","sources":["../src/syncUI.tsx","../src/index.ts"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\n\nconst useComponentDidMount = (fn: Parameters<typeof useEffect>[0]) => {\n useEffect(fn, []);\n};\n\n// this function broke the working of the hot reloading\n/*\nconst getSingletonComponentCheck = (errorMsg: string) => {\n let globalMountCounter = 0;\n\n return () => {\n useComponentDidMount(() => {\n if (globalMountCounter > 0) throw new Error(errorMsg);\n globalMountCounter++;\n });\n return <React.Fragment />;\n };\n};\n*/\n\n// ------------------------------------------------------------------------------------\n// TODO: there is tsdx old typescript parser and new ts fancy syntax is not working...\n// https://github.com/jaredpalmer/tsdx/issues/200\n// type PromiseQueueAPI<Data, ResolveValue> = ReturnType<typeof usePromiseQueue<any, any>>\ntype PromiseQueueAPI<Data, ResolveValue> = {\n head?: {\n data: Data;\n resolve: (value: ResolveValue) => void;\n reject: (reason?: any) => void;\n };\n push: (data: Data) => Promise<ResolveValue>;\n};\n\nexport const usePromiseQueue = <Data, ResolveValue = void>(): PromiseQueueAPI<\n Data,\n ResolveValue\n> => {\n const [asyncQueue, setAsyncQueue] = useState(\n [] as {\n data: Data;\n resolve: (arg: ResolveValue) => void;\n reject: (arg: any) => void;\n }[]\n );\n\n const push = useCallback((data: Data) => {\n return new Promise<ResolveValue>((resolve, reject) =>\n setAsyncQueue(p => [...p, { data, resolve, reject }])\n );\n }, []);\n\n const resolveHeadItem = useCallback((value: ResolveValue) => {\n setAsyncQueue(queue => {\n const [first, ...rest] = queue;\n first?.resolve(value);\n return rest;\n });\n }, []);\n\n const rejectHeadItem = useCallback((reason?: any) => {\n setAsyncQueue(queue => {\n const [first, ...rest] = queue;\n first?.reject(reason);\n return rest;\n });\n }, []);\n\n return {\n head: asyncQueue[0]\n ? {\n data: asyncQueue[0]?.data,\n resolve: resolveHeadItem,\n reject: rejectHeadItem\n }\n : undefined,\n push\n };\n};\n\n// ------------------------------------------------------------------------------------\n\nexport const syncUIFactory = () => {\n const mutSyncUIComponentsRenderQueue = [] as React.FC<\n PromiseQueueAPI<any, any>\n >[];\n\n /*\n // this check broke the working of the hot reloading\n const ThrowIfMoreInstances = getSingletonComponentCheck(\n \"<SyncUI /> has to be initialized only once\"\n );\n */\n\n return {\n makeSyncUI: <InputData, ResolveValue = void>(\n SyncUIUserComp: React.FC<{\n data: InputData;\n resolve: (value: ResolveValue) => void;\n reject: (reason?: any) => void;\n }>\n ) => {\n type QItem = PromiseQueueAPI<\n { type: Symbol; inputData: InputData },\n ResolveValue\n >;\n\n const _debugName =\n SyncUIUserComp.displayName ??\n SyncUIUserComp.name ??\n \"uniqSymbolMessageType\";\n\n const syncUIComponentType = Symbol(_debugName);\n\n // object pointer reference with the push key has to be there to change returned mutable reference object while the function is already called\n const singletonSyncUIRef = {\n push: undefined as undefined | QItem[\"push\"]\n };\n\n const SyncUISingletonComponent = (props: QItem) => {\n useComponentDidMount(() => {\n singletonSyncUIRef.push = props.push;\n return () => (singletonSyncUIRef.push = undefined);\n });\n\n if (!props.head) return null;\n if (props.head.data.type !== syncUIComponentType) return null;\n\n return (\n <SyncUIUserComp\n data={props.head.data.inputData}\n resolve={props.head.resolve}\n reject={props.head.reject}\n />\n );\n };\n\n mutSyncUIComponentsRenderQueue.push(SyncUISingletonComponent);\n\n return (input: InputData) => {\n if (!singletonSyncUIRef.push)\n throw new Error(`You have to initialize <SyncUI />`);\n return singletonSyncUIRef.push({\n type: syncUIComponentType,\n inputData: input\n });\n };\n },\n SyncUI: () => {\n const queue = usePromiseQueue();\n return (\n <>\n {/* <ThrowIfMoreInstances /> */}\n {mutSyncUIComponentsRenderQueue.map((SyncComp, key) => (\n <React.Fragment key={key}>\n <SyncComp {...queue} />\n </React.Fragment>\n ))}\n </>\n );\n }\n };\n};\n","import { syncUIFactory as _syncUIFactory } from \"./syncUI\";\nexport const syncUIFactory = _syncUIFactory;\nexport const { makeSyncUI, SyncUI } = syncUIFactory();\n"],"names":["useComponentDidMount","fn","useEffect","usePromiseQueue","_useState","useState","asyncQueue","setAsyncQueue","push","useCallback","data","Promise","resolve","reject","p","concat","resolveHeadItem","value","queue","first","rest","slice","rejectHeadItem","reason","head","_asyncQueue$","undefined","syncUIFactory","mutSyncUIComponentsRenderQueue","makeSyncUI","SyncUIUserComp","_debugName","_ref","_SyncUIUserComp$displ","displayName","name","syncUIComponentType","Symbol","singletonSyncUIRef","SyncUISingletonComponent","props","type","React","inputData","input","Error","SyncUI","map","SyncComp","key","Fragment","_syncUIFactory","_syncUIFactory2"],"mappings":";;;;;;;;;AAEA,IAAMA,oBAAoB,GAAG,SAAvBA,oBAAoBA,CAAIC,EAAmC;EAC/DC,eAAS,CAACD,EAAE,EAAE,EAAE,CAAC;AACnB,CAAC;AA8BM,IAAME,eAAe,GAAG,SAAlBA,eAAeA;;EAI1B,IAAAC,SAAA,GAAoCC,cAAQ,CAC1C,EAIG,CACJ;IANMC,UAAU,GAAAF,SAAA;IAAEG,aAAa,GAAAH,SAAA;EAQhC,IAAMI,IAAI,GAAGC,iBAAW,CAAC,UAACC,IAAU;IAClC,OAAO,IAAIC,OAAO,CAAe,UAACC,OAAO,EAAEC,MAAM;MAAA,OAC/CN,aAAa,CAAC,UAAAO,CAAC;QAAA,UAAAC,MAAA,CAAQD,CAAC,GAAE;UAAEJ,IAAI,EAAJA,IAAI;UAAEE,OAAO,EAAPA,OAAO;UAAEC,MAAM,EAANA;SAAQ;OAAC,CAAC;MACtD;GACF,EAAE,EAAE,CAAC;EAEN,IAAMG,eAAe,GAAGP,iBAAW,CAAC,UAACQ,KAAmB;IACtDV,aAAa,CAAC,UAAAW,KAA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,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,r=function(){var e=[];return{makeSyncUI:function(r){var u,a,c=null!=(u=null!=(a=r.displayName)?a:r.name)?u:"uniqSymbolMessageType",l=Symbol(c),o={push:void 0};return e.push((function(e){return t.useEffect((function(){return o.push=e.push,function(){return o.push=void 0}}),[]),e.head?e.head.data.type!==l?null:n.createElement(r,{data:e.head.data.inputData,resolve:e.head.resolve,reject:e.head.reject}):null})),function(e){if(!o.push)throw new Error("You have to initialize <SyncUI />");return o.push({type:l,inputData:e})}},SyncUI:function(){var r,u,a,c,l,o,i,s=(a=(u=t.useState([]))[0],c=u[1],l=t.useCallback((function(e){return new Promise((function(t,n){return c((function(r){return[].concat(r,[{data:e,resolve:t,reject:n}])}))}))}),[]),o=t.useCallback((function(e){c((function(t){var n=t[0],r=t.slice(1);return null==n||n.resolve(e),r}))}),[]),i=t.useCallback((function(e){c((function(t){var n=t[0],r=t.slice(1);return null==n||n.reject(e),r}))}),[]),{head:a[0]?{data:null==(r=a[0])?void 0:r.data,resolve:o,reject:i}:void 0,push:l});return n.createElement(n.Fragment,null,e.map((function(e,t){return n.createElement(n.Fragment,{key:t},n.createElement(e,Object.assign({},s)))})))}}},u=r(),a=u.makeSyncUI;exports.SyncUI=u.SyncUI,exports.makeSyncUI=a,exports.syncUIFactory=r;
|
|
2
2
|
//# sourceMappingURL=react-sync-ui.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-sync-ui.cjs.production.min.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"react-sync-ui.cjs.production.min.js","sources":["../src/index.ts","../src/syncUI.tsx"],"sourcesContent":["import { syncUIFactory as _syncUIFactory } from \"./syncUI\";\nexport const syncUIFactory = _syncUIFactory;\nexport const { makeSyncUI, SyncUI } = syncUIFactory();\n","import React, { useCallback, useEffect, useState } from \"react\";\n\nconst useComponentDidMount = (fn: Parameters<typeof useEffect>[0]) => {\n useEffect(fn, []);\n};\n\n// this function broke the working of the hot reloading\n/*\nconst getSingletonComponentCheck = (errorMsg: string) => {\n let globalMountCounter = 0;\n\n return () => {\n useComponentDidMount(() => {\n if (globalMountCounter > 0) throw new Error(errorMsg);\n globalMountCounter++;\n });\n return <React.Fragment />;\n };\n};\n*/\n\n// ------------------------------------------------------------------------------------\n// TODO: there is tsdx old typescript parser and new ts fancy syntax is not working...\n// https://github.com/jaredpalmer/tsdx/issues/200\n// type PromiseQueueAPI<Data, ResolveValue> = ReturnType<typeof usePromiseQueue<any, any>>\ntype PromiseQueueAPI<Data, ResolveValue> = {\n head?: {\n data: Data;\n resolve: (value: ResolveValue) => void;\n reject: (reason?: any) => void;\n };\n push: (data: Data) => Promise<ResolveValue>;\n};\n\nexport const usePromiseQueue = <Data, ResolveValue = void>(): PromiseQueueAPI<\n Data,\n ResolveValue\n> => {\n const [asyncQueue, setAsyncQueue] = useState(\n [] as {\n data: Data;\n resolve: (arg: ResolveValue) => void;\n reject: (arg: any) => void;\n }[]\n );\n\n const push = useCallback((data: Data) => {\n return new Promise<ResolveValue>((resolve, reject) =>\n setAsyncQueue(p => [...p, { data, resolve, reject }])\n );\n }, []);\n\n const resolveHeadItem = useCallback((value: ResolveValue) => {\n setAsyncQueue(queue => {\n const [first, ...rest] = queue;\n first?.resolve(value);\n return rest;\n });\n }, []);\n\n const rejectHeadItem = useCallback((reason?: any) => {\n setAsyncQueue(queue => {\n const [first, ...rest] = queue;\n first?.reject(reason);\n return rest;\n });\n }, []);\n\n return {\n head: asyncQueue[0]\n ? {\n data: asyncQueue[0]?.data,\n resolve: resolveHeadItem,\n reject: rejectHeadItem\n }\n : undefined,\n push\n };\n};\n\n// ------------------------------------------------------------------------------------\n\nexport const syncUIFactory = () => {\n const mutSyncUIComponentsRenderQueue = [] as React.FC<\n PromiseQueueAPI<any, any>\n >[];\n\n /*\n // this check broke the working of the hot reloading\n const ThrowIfMoreInstances = getSingletonComponentCheck(\n \"<SyncUI /> has to be initialized only once\"\n );\n */\n\n return {\n makeSyncUI: <InputData, ResolveValue = void>(\n SyncUIUserComp: React.FC<{\n data: InputData;\n resolve: (value: ResolveValue) => void;\n reject: (reason?: any) => void;\n }>\n ) => {\n type QItem = PromiseQueueAPI<\n { type: Symbol; inputData: InputData },\n ResolveValue\n >;\n\n const _debugName =\n SyncUIUserComp.displayName ??\n SyncUIUserComp.name ??\n \"uniqSymbolMessageType\";\n\n const syncUIComponentType = Symbol(_debugName);\n\n // object pointer reference with the push key has to be there to change returned mutable reference object while the function is already called\n const singletonSyncUIRef = {\n push: undefined as undefined | QItem[\"push\"]\n };\n\n const SyncUISingletonComponent = (props: QItem) => {\n useComponentDidMount(() => {\n singletonSyncUIRef.push = props.push;\n return () => (singletonSyncUIRef.push = undefined);\n });\n\n if (!props.head) return null;\n if (props.head.data.type !== syncUIComponentType) return null;\n\n return (\n <SyncUIUserComp\n data={props.head.data.inputData}\n resolve={props.head.resolve}\n reject={props.head.reject}\n />\n );\n };\n\n mutSyncUIComponentsRenderQueue.push(SyncUISingletonComponent);\n\n return (input: InputData) => {\n if (!singletonSyncUIRef.push)\n throw new Error(`You have to initialize <SyncUI />`);\n return singletonSyncUIRef.push({\n type: syncUIComponentType,\n inputData: input\n });\n };\n },\n SyncUI: () => {\n const queue = usePromiseQueue();\n return (\n <>\n {/* <ThrowIfMoreInstances /> */}\n {mutSyncUIComponentsRenderQueue.map((SyncComp, key) => (\n <React.Fragment key={key}>\n <SyncComp {...queue} />\n </React.Fragment>\n ))}\n </>\n );\n }\n };\n};\n"],"names":["syncUIFactory","mutSyncUIComponentsRenderQueue","makeSyncUI","SyncUIUserComp","_debugName","_ref","_SyncUIUserComp$displ","displayName","name","syncUIComponentType","Symbol","singletonSyncUIRef","push","undefined","props","useEffect","head","data","type","React","inputData","resolve","reject","input","Error","SyncUI","_useState","asyncQueue","setAsyncQueue","resolveHeadItem","rejectHeadItem","queue","useState","useCallback","Promise","p","concat","value","first","rest","slice","reason","_asyncQueue$","map","SyncComp","key","Fragment","_syncUIFactory2"],"mappings":"oJACaA,ECiFgB,WAC3B,IAAMC,EAAiC,GAWvC,MAAO,CACLC,WAAY,SACVC,WAWMC,SAAUC,SAAAC,EACdH,EAAeI,aAAWD,EAC1BH,EAAeK,MAAIH,EACnB,wBAEII,EAAsBC,OAAON,GAG7BO,EAAqB,CACzBC,UAAMC,GAuBR,OAFAZ,EAA+BW,MAlBE,SAACE,GAMhC,OA1HNC,aAqH2B,WAEnB,OADAJ,EAAmBC,KAAOE,EAAMF,KACzB,WAAA,OAAOD,EAAmBC,UAAOC,KAvHlC,IA0HHC,EAAME,KACPF,EAAME,KAAKC,KAAKC,OAAST,EAA4B,KAGvDU,gBAAChB,GACCc,KAAMH,EAAME,KAAKC,KAAKG,UACtBC,QAASP,EAAME,KAAKK,QACpBC,OAAQR,EAAME,KAAKM,SAPC,QAcnB,SAACC,GACN,IAAKZ,EAAmBC,KACtB,MAAM,IAAIY,2CACZ,OAAOb,EAAmBC,KAAK,CAC7BM,KAAMT,EACNW,UAAWG,MAIjBE,OAAQ,WACN,MA/GJC,EAAOC,EAAYC,EAQbhB,EAMAiB,EAQAC,EAyFIC,GA/GHJ,GAAPD,EAAoCM,WAClC,QADiBJ,EAAaF,KAQ1Bd,EAAOqB,eAAY,SAAChB,GACxB,OAAO,IAAIiB,SAAsB,SAACb,EAASC,GAAM,OAC/CM,GAAc,SAAAO,GAAC,SAAAC,OAAQD,GAAG,CAAElB,KAAAA,EAAMI,QAAAA,EAASC,OAAAA,aAE5C,IAEGO,EAAkBI,eAAY,SAACI,GACnCT,GAAc,SAAAG,GACZ,IAAOO,EAAkBP,KAARQ,EAAQR,EAAKS,SAE9B,aADAF,GAAAA,EAAOjB,QAAQgB,GACRE,OAER,IAEGT,EAAiBG,eAAY,SAACQ,GAClCb,GAAc,SAAAG,GACZ,IAAOO,EAAkBP,KAARQ,EAAQR,EAAKS,SAE9B,aADAF,GAAAA,EAAOhB,OAAOmB,GACPF,OAER,IAEI,CACLvB,KAAMW,EAAW,GACb,CACEV,YAAIyB,EAAEf,EAAW,WAAXe,EAAezB,KACrBI,QAASQ,EACTP,OAAQQ,QAEVjB,EACJD,KAAAA,IA0EE,OACEO,gCAEGlB,EAA+B0C,KAAI,SAACC,EAAUC,GAAG,OAChD1B,gBAACA,EAAM2B,UAASD,IAAKA,GACnB1B,gBAACyB,mBAAab,YDzJrBgB,EAA+B/C,IAAvBE,EAAU6C,EAAV7C,0BAAkB6C,EAANtB"}
|
|
@@ -3,25 +3,11 @@ import React, { useState, useCallback, useEffect } from 'react';
|
|
|
3
3
|
var useComponentDidMount = function useComponentDidMount(fn) {
|
|
4
4
|
useEffect(fn, []);
|
|
5
5
|
};
|
|
6
|
-
|
|
7
|
-
var getSingletonComponentCheck = function getSingletonComponentCheck(errorMsg) {
|
|
8
|
-
var globalMountCounter = 0;
|
|
9
|
-
return function () {
|
|
10
|
-
useComponentDidMount(function () {
|
|
11
|
-
if (globalMountCounter > 0) throw new Error(errorMsg);
|
|
12
|
-
globalMountCounter++;
|
|
13
|
-
});
|
|
14
|
-
return React.createElement(React.Fragment, null);
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
6
|
var usePromiseQueue = function usePromiseQueue() {
|
|
19
7
|
var _asyncQueue$;
|
|
20
|
-
|
|
21
8
|
var _useState = useState([]),
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
asyncQueue = _useState[0],
|
|
10
|
+
setAsyncQueue = _useState[1];
|
|
25
11
|
var push = useCallback(function (data) {
|
|
26
12
|
return new Promise(function (resolve, reject) {
|
|
27
13
|
return setAsyncQueue(function (p) {
|
|
@@ -36,7 +22,7 @@ var usePromiseQueue = function usePromiseQueue() {
|
|
|
36
22
|
var resolveHeadItem = useCallback(function (value) {
|
|
37
23
|
setAsyncQueue(function (queue) {
|
|
38
24
|
var first = queue[0],
|
|
39
|
-
|
|
25
|
+
rest = queue.slice(1);
|
|
40
26
|
first == null ? void 0 : first.resolve(value);
|
|
41
27
|
return rest;
|
|
42
28
|
});
|
|
@@ -44,7 +30,7 @@ var usePromiseQueue = function usePromiseQueue() {
|
|
|
44
30
|
var rejectHeadItem = useCallback(function (reason) {
|
|
45
31
|
setAsyncQueue(function (queue) {
|
|
46
32
|
var first = queue[0],
|
|
47
|
-
|
|
33
|
+
rest = queue.slice(1);
|
|
48
34
|
first == null ? void 0 : first.reject(reason);
|
|
49
35
|
return rest;
|
|
50
36
|
});
|
|
@@ -57,23 +43,25 @@ var usePromiseQueue = function usePromiseQueue() {
|
|
|
57
43
|
} : undefined,
|
|
58
44
|
push: push
|
|
59
45
|
};
|
|
60
|
-
};
|
|
61
|
-
|
|
46
|
+
};
|
|
47
|
+
// ------------------------------------------------------------------------------------
|
|
62
48
|
var syncUIFactory = function syncUIFactory() {
|
|
63
49
|
var mutSyncUIComponentsRenderQueue = [];
|
|
64
|
-
|
|
50
|
+
/*
|
|
51
|
+
// this check broke the working of the hot reloading
|
|
52
|
+
const ThrowIfMoreInstances = getSingletonComponentCheck(
|
|
53
|
+
"<SyncUI /> has to be initialized only once"
|
|
54
|
+
);
|
|
55
|
+
*/
|
|
65
56
|
return {
|
|
66
57
|
makeSyncUI: function makeSyncUI(SyncUIUserComp) {
|
|
67
58
|
var _ref, _SyncUIUserComp$displ;
|
|
68
|
-
|
|
69
59
|
var _debugName = (_ref = (_SyncUIUserComp$displ = SyncUIUserComp.displayName) != null ? _SyncUIUserComp$displ : SyncUIUserComp.name) != null ? _ref : "uniqSymbolMessageType";
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
60
|
+
var syncUIComponentType = Symbol(_debugName);
|
|
61
|
+
// object pointer reference with the push key has to be there to change returned mutable reference object while the function is already called
|
|
73
62
|
var singletonSyncUIRef = {
|
|
74
63
|
push: undefined
|
|
75
64
|
};
|
|
76
|
-
|
|
77
65
|
var SyncUISingletonComponent = function SyncUISingletonComponent(props) {
|
|
78
66
|
useComponentDidMount(function () {
|
|
79
67
|
singletonSyncUIRef.push = props.push;
|
|
@@ -89,7 +77,6 @@ var syncUIFactory = function syncUIFactory() {
|
|
|
89
77
|
reject: props.head.reject
|
|
90
78
|
});
|
|
91
79
|
};
|
|
92
|
-
|
|
93
80
|
mutSyncUIComponentsRenderQueue.push(SyncUISingletonComponent);
|
|
94
81
|
return function (input) {
|
|
95
82
|
if (!singletonSyncUIRef.push) throw new Error("You have to initialize <SyncUI />");
|
|
@@ -101,7 +88,7 @@ var syncUIFactory = function syncUIFactory() {
|
|
|
101
88
|
},
|
|
102
89
|
SyncUI: function SyncUI() {
|
|
103
90
|
var queue = usePromiseQueue();
|
|
104
|
-
return React.createElement(React.Fragment, null,
|
|
91
|
+
return React.createElement(React.Fragment, null, mutSyncUIComponentsRenderQueue.map(function (SyncComp, key) {
|
|
105
92
|
return React.createElement(React.Fragment, {
|
|
106
93
|
key: key
|
|
107
94
|
}, React.createElement(SyncComp, Object.assign({}, queue)));
|
|
@@ -111,10 +98,9 @@ var syncUIFactory = function syncUIFactory() {
|
|
|
111
98
|
};
|
|
112
99
|
|
|
113
100
|
var syncUIFactory$1 = syncUIFactory;
|
|
114
|
-
|
|
115
101
|
var _syncUIFactory2 = /*#__PURE__*/syncUIFactory$1(),
|
|
116
|
-
|
|
117
|
-
|
|
102
|
+
makeSyncUI = _syncUIFactory2.makeSyncUI,
|
|
103
|
+
SyncUI = _syncUIFactory2.SyncUI;
|
|
118
104
|
|
|
119
105
|
export { SyncUI, makeSyncUI, syncUIFactory$1 as syncUIFactory };
|
|
120
106
|
//# sourceMappingURL=react-sync-ui.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-sync-ui.esm.js","sources":["../src/syncUI.tsx","../src/index.ts"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\n\nconst useComponentDidMount = (fn: Parameters<typeof useEffect>[0]) => {\n useEffect(fn, []);\n};\n\nconst getSingletonComponentCheck = (errorMsg: string) => {\n let globalMountCounter = 0;\n\n return () => {\n useComponentDidMount(() => {\n if (globalMountCounter > 0) throw new Error(errorMsg);\n globalMountCounter++;\n });\n return <React.Fragment />;\n };\n};\n\n// ------------------------------------------------------------------------------------\n// TODO: there is tsdx old typescript parser and new ts fancy syntax is not working...\n// https://github.com/jaredpalmer/tsdx/issues/200\n// type PromiseQueueAPI<Data, ResolveValue> = ReturnType<typeof usePromiseQueue<any, any>>\ntype PromiseQueueAPI<Data, ResolveValue> = {\n head?: {\n data: Data;\n resolve: (value: ResolveValue) => void;\n reject: (reason?: any) => void;\n };\n push: (data: Data) => Promise<ResolveValue>;\n};\n\nexport const usePromiseQueue = <Data, ResolveValue = void>(): PromiseQueueAPI<\n Data,\n ResolveValue\n> => {\n const [asyncQueue, setAsyncQueue] = useState(\n [] as {\n data: Data;\n resolve: (arg: ResolveValue) => void;\n reject: (arg: any) => void;\n }[]\n );\n\n const push = useCallback((data: Data) => {\n return new Promise<ResolveValue>((resolve, reject) =>\n setAsyncQueue(p => [...p, { data, resolve, reject }])\n );\n }, []);\n\n const resolveHeadItem = useCallback((value: ResolveValue) => {\n setAsyncQueue(queue => {\n const [first, ...rest] = queue;\n first?.resolve(value);\n return rest;\n });\n }, []);\n\n const rejectHeadItem = useCallback((reason?: any) => {\n setAsyncQueue(queue => {\n const [first, ...rest] = queue;\n first?.reject(reason);\n return rest;\n });\n }, []);\n\n return {\n head: asyncQueue[0]\n ? {\n data: asyncQueue[0]?.data,\n resolve: resolveHeadItem,\n reject: rejectHeadItem\n }\n : undefined,\n push\n };\n};\n\n// ------------------------------------------------------------------------------------\n\nexport const syncUIFactory = () => {\n const mutSyncUIComponentsRenderQueue = [] as React.FC<\n PromiseQueueAPI<any, any>\n >[];\n\n const ThrowIfMoreInstances = getSingletonComponentCheck(\n \"<SyncUI /> has to be initialized only once\"\n );\n\n return {\n makeSyncUI: <InputData, ResolveValue = void>(\n SyncUIUserComp: React.FC<{\n data: InputData;\n resolve: (value: ResolveValue) => void;\n reject: (reason?: any) => void;\n }>\n ) => {\n type QItem = PromiseQueueAPI<\n { type: Symbol; inputData: InputData },\n ResolveValue\n >;\n\n const _debugName =\n SyncUIUserComp.displayName ??\n SyncUIUserComp.name ??\n \"uniqSymbolMessageType\";\n\n const syncUIComponentType = Symbol(_debugName);\n\n // object pointer reference with the push key has to be there to change returned mutable reference object while the function is already called\n const singletonSyncUIRef = {\n push: undefined as undefined | QItem[\"push\"]\n };\n\n const SyncUISingletonComponent = (props: QItem) => {\n useComponentDidMount(() => {\n singletonSyncUIRef.push = props.push;\n return () => (singletonSyncUIRef.push = undefined);\n });\n\n if (!props.head) return null;\n if (props.head.data.type !== syncUIComponentType) return null;\n\n return (\n <SyncUIUserComp\n data={props.head.data.inputData}\n resolve={props.head.resolve}\n reject={props.head.reject}\n />\n );\n };\n\n mutSyncUIComponentsRenderQueue.push(SyncUISingletonComponent);\n\n return (input: InputData) => {\n if (!singletonSyncUIRef.push)\n throw new Error(`You have to initialize <SyncUI />`);\n return singletonSyncUIRef.push({\n type: syncUIComponentType,\n inputData: input\n });\n };\n },\n SyncUI: () => {\n const queue = usePromiseQueue();\n return (\n <>\n <ThrowIfMoreInstances
|
|
1
|
+
{"version":3,"file":"react-sync-ui.esm.js","sources":["../src/syncUI.tsx","../src/index.ts"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\n\nconst useComponentDidMount = (fn: Parameters<typeof useEffect>[0]) => {\n useEffect(fn, []);\n};\n\n// this function broke the working of the hot reloading\n/*\nconst getSingletonComponentCheck = (errorMsg: string) => {\n let globalMountCounter = 0;\n\n return () => {\n useComponentDidMount(() => {\n if (globalMountCounter > 0) throw new Error(errorMsg);\n globalMountCounter++;\n });\n return <React.Fragment />;\n };\n};\n*/\n\n// ------------------------------------------------------------------------------------\n// TODO: there is tsdx old typescript parser and new ts fancy syntax is not working...\n// https://github.com/jaredpalmer/tsdx/issues/200\n// type PromiseQueueAPI<Data, ResolveValue> = ReturnType<typeof usePromiseQueue<any, any>>\ntype PromiseQueueAPI<Data, ResolveValue> = {\n head?: {\n data: Data;\n resolve: (value: ResolveValue) => void;\n reject: (reason?: any) => void;\n };\n push: (data: Data) => Promise<ResolveValue>;\n};\n\nexport const usePromiseQueue = <Data, ResolveValue = void>(): PromiseQueueAPI<\n Data,\n ResolveValue\n> => {\n const [asyncQueue, setAsyncQueue] = useState(\n [] as {\n data: Data;\n resolve: (arg: ResolveValue) => void;\n reject: (arg: any) => void;\n }[]\n );\n\n const push = useCallback((data: Data) => {\n return new Promise<ResolveValue>((resolve, reject) =>\n setAsyncQueue(p => [...p, { data, resolve, reject }])\n );\n }, []);\n\n const resolveHeadItem = useCallback((value: ResolveValue) => {\n setAsyncQueue(queue => {\n const [first, ...rest] = queue;\n first?.resolve(value);\n return rest;\n });\n }, []);\n\n const rejectHeadItem = useCallback((reason?: any) => {\n setAsyncQueue(queue => {\n const [first, ...rest] = queue;\n first?.reject(reason);\n return rest;\n });\n }, []);\n\n return {\n head: asyncQueue[0]\n ? {\n data: asyncQueue[0]?.data,\n resolve: resolveHeadItem,\n reject: rejectHeadItem\n }\n : undefined,\n push\n };\n};\n\n// ------------------------------------------------------------------------------------\n\nexport const syncUIFactory = () => {\n const mutSyncUIComponentsRenderQueue = [] as React.FC<\n PromiseQueueAPI<any, any>\n >[];\n\n /*\n // this check broke the working of the hot reloading\n const ThrowIfMoreInstances = getSingletonComponentCheck(\n \"<SyncUI /> has to be initialized only once\"\n );\n */\n\n return {\n makeSyncUI: <InputData, ResolveValue = void>(\n SyncUIUserComp: React.FC<{\n data: InputData;\n resolve: (value: ResolveValue) => void;\n reject: (reason?: any) => void;\n }>\n ) => {\n type QItem = PromiseQueueAPI<\n { type: Symbol; inputData: InputData },\n ResolveValue\n >;\n\n const _debugName =\n SyncUIUserComp.displayName ??\n SyncUIUserComp.name ??\n \"uniqSymbolMessageType\";\n\n const syncUIComponentType = Symbol(_debugName);\n\n // object pointer reference with the push key has to be there to change returned mutable reference object while the function is already called\n const singletonSyncUIRef = {\n push: undefined as undefined | QItem[\"push\"]\n };\n\n const SyncUISingletonComponent = (props: QItem) => {\n useComponentDidMount(() => {\n singletonSyncUIRef.push = props.push;\n return () => (singletonSyncUIRef.push = undefined);\n });\n\n if (!props.head) return null;\n if (props.head.data.type !== syncUIComponentType) return null;\n\n return (\n <SyncUIUserComp\n data={props.head.data.inputData}\n resolve={props.head.resolve}\n reject={props.head.reject}\n />\n );\n };\n\n mutSyncUIComponentsRenderQueue.push(SyncUISingletonComponent);\n\n return (input: InputData) => {\n if (!singletonSyncUIRef.push)\n throw new Error(`You have to initialize <SyncUI />`);\n return singletonSyncUIRef.push({\n type: syncUIComponentType,\n inputData: input\n });\n };\n },\n SyncUI: () => {\n const queue = usePromiseQueue();\n return (\n <>\n {/* <ThrowIfMoreInstances /> */}\n {mutSyncUIComponentsRenderQueue.map((SyncComp, key) => (\n <React.Fragment key={key}>\n <SyncComp {...queue} />\n </React.Fragment>\n ))}\n </>\n );\n }\n };\n};\n","import { syncUIFactory as _syncUIFactory } from \"./syncUI\";\nexport const syncUIFactory = _syncUIFactory;\nexport const { makeSyncUI, SyncUI } = syncUIFactory();\n"],"names":["useComponentDidMount","fn","useEffect","usePromiseQueue","_useState","useState","asyncQueue","setAsyncQueue","push","useCallback","data","Promise","resolve","reject","p","concat","resolveHeadItem","value","queue","first","rest","slice","rejectHeadItem","reason","head","_asyncQueue$","undefined","syncUIFactory","mutSyncUIComponentsRenderQueue","makeSyncUI","SyncUIUserComp","_debugName","_ref","_SyncUIUserComp$displ","displayName","name","syncUIComponentType","Symbol","singletonSyncUIRef","SyncUISingletonComponent","props","type","React","inputData","input","Error","SyncUI","map","SyncComp","key","Fragment","_syncUIFactory","_syncUIFactory2"],"mappings":";;AAEA,IAAMA,oBAAoB,GAAG,SAAvBA,oBAAoBA,CAAIC,EAAmC;EAC/DC,SAAS,CAACD,EAAE,EAAE,EAAE,CAAC;AACnB,CAAC;AA8BM,IAAME,eAAe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F;IACDE,MAAM,EAAE,SAAAA;MACN,IAAM5B,KAAK,GAAGf,eAAe,EAAE;MAC/B,OACEuC,0CAEGd,8BAA8B,CAACmB,GAAG,CAAC,UAACC,QAAQ,EAAEC,GAAG;QAAA,OAChDP,oBAACA,KAAK,CAACQ,QAAQ;UAACD,GAAG,EAAEA;WACnBP,oBAACM,QAAQ,oBAAK9B,KAAK,EAAI,CACR;OAClB,CAAC,CACD;;GAGR;AACH,CAAC;;ICjKYS,eAAa,GAAGwB;AACtB,IAAAC,eAAA,gBAA+BzB,eAAa,EAAE;EAAtCE,UAAU,GAAAuB,eAAA,CAAVvB,UAAU;EAAEiB,MAAM,GAAAM,eAAA,CAANN,MAAM;;;;"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-sync-ui",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"repository": "https://github.com/Svehla/react-sync-ui",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jakub Švehla",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
|
-
"module": "dist/
|
|
8
|
+
"module": "dist/react-sync-ui.esm.js",
|
|
9
9
|
"typings": "dist/index.d.ts",
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
package/src/syncUI.tsx
CHANGED
|
@@ -4,6 +4,8 @@ const useComponentDidMount = (fn: Parameters<typeof useEffect>[0]) => {
|
|
|
4
4
|
useEffect(fn, []);
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
+
// this function broke the working of the hot reloading
|
|
8
|
+
/*
|
|
7
9
|
const getSingletonComponentCheck = (errorMsg: string) => {
|
|
8
10
|
let globalMountCounter = 0;
|
|
9
11
|
|
|
@@ -15,6 +17,7 @@ const getSingletonComponentCheck = (errorMsg: string) => {
|
|
|
15
17
|
return <React.Fragment />;
|
|
16
18
|
};
|
|
17
19
|
};
|
|
20
|
+
*/
|
|
18
21
|
|
|
19
22
|
// ------------------------------------------------------------------------------------
|
|
20
23
|
// TODO: there is tsdx old typescript parser and new ts fancy syntax is not working...
|
|
@@ -82,9 +85,12 @@ export const syncUIFactory = () => {
|
|
|
82
85
|
PromiseQueueAPI<any, any>
|
|
83
86
|
>[];
|
|
84
87
|
|
|
88
|
+
/*
|
|
89
|
+
// this check broke the working of the hot reloading
|
|
85
90
|
const ThrowIfMoreInstances = getSingletonComponentCheck(
|
|
86
91
|
"<SyncUI /> has to be initialized only once"
|
|
87
92
|
);
|
|
93
|
+
*/
|
|
88
94
|
|
|
89
95
|
return {
|
|
90
96
|
makeSyncUI: <InputData, ResolveValue = void>(
|
|
@@ -144,7 +150,7 @@ export const syncUIFactory = () => {
|
|
|
144
150
|
const queue = usePromiseQueue();
|
|
145
151
|
return (
|
|
146
152
|
<>
|
|
147
|
-
<ThrowIfMoreInstances />
|
|
153
|
+
{/* <ThrowIfMoreInstances /> */}
|
|
148
154
|
{mutSyncUIComponentsRenderQueue.map((SyncComp, key) => (
|
|
149
155
|
<React.Fragment key={key}>
|
|
150
156
|
<SyncComp {...queue} />
|