@fto-consult/expo-ui 6.86.1 → 6.87.2
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/package.json
CHANGED
@@ -114,19 +114,21 @@ const TableDataSelectField = React.forwardRef(({foreignKeyColumn,foreignKeyLabel
|
|
114
114
|
}
|
115
115
|
const hasRefreshedRef = React.useRef(false);
|
116
116
|
React.useEffect(()=>{
|
117
|
-
|
118
|
-
|
119
|
-
const onUpsertData = ()=>{return isMounted()?context.refresh():undefined};
|
120
|
-
APP.on(actions.upsert(foreignKeyTable),onUpsertData);
|
121
|
-
APP.on(actions.onRemove(foreignKeyTable),onUpsertData);
|
122
|
-
return ()=>{
|
123
|
-
APP.off(actions.upsert(foreignKeyTable),onUpsertData);
|
124
|
-
APP.off(actions.onRemove(foreignKeyTable),onUpsertData);
|
125
|
-
};
|
117
|
+
if(bindUpsert2RemoveEvents === false || !(foreignKeyTableStr)){
|
118
|
+
return ()=>{}
|
126
119
|
}
|
120
|
+
const onUpsertData = ()=>{
|
121
|
+
return isMounted()?context.refresh():undefined
|
122
|
+
};
|
123
|
+
APP.on(actions.upsert(foreignKeyTableStr),onUpsertData);
|
124
|
+
APP.on(actions.onRemove(foreignKeyTableStr),onUpsertData);
|
127
125
|
return ()=>{
|
128
|
-
|
129
|
-
|
126
|
+
APP.off(actions.upsert(foreignKeyTableStr),onUpsertData);
|
127
|
+
APP.off(actions.onRemove(foreignKeyTableStr),onUpsertData);
|
128
|
+
};
|
129
|
+
},[foreignKeyTableStr,bindUpsert2RemoveEvents])
|
130
|
+
React.useEffect(()=>{
|
131
|
+
context.refresh();
|
130
132
|
},[]);
|
131
133
|
|
132
134
|
let dat = isNonNullString(foreignKeyColumnValue)? {
|
package/src/context/hooks.js
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
import Dimensions from "$cplatform/dimensions";
|
4
2
|
import useStableMemo from "$react/useStableMemo";
|
5
3
|
import { useWindowDimensions } from "$cdimensions";
|
6
|
-
import {isObj,isNonNullString} from "$cutils";
|
4
|
+
import {isObj,isNonNullString,extendObj} from "$cutils";
|
7
5
|
import { StyleSheet } from "react-native";
|
8
6
|
import { createContext,useContext as useReactContext } from "react";
|
7
|
+
import _useSWR from "$swr";
|
9
8
|
|
10
9
|
export const ExpoUIContext = createContext(null);
|
11
10
|
|
@@ -17,6 +16,30 @@ export const useContext = useExpoUI;
|
|
17
16
|
|
18
17
|
export const useApp = useContext;
|
19
18
|
|
19
|
+
export const useSWR = (path,options)=>{
|
20
|
+
const {swrConfig} = useExpoUI();
|
21
|
+
const host = `${defaultStr(process.env.API_HOST).trim().rtrim("/")}/${path}`;
|
22
|
+
const isLocalHost = host.includes("127.0.0.1") || host.includes("localhost");
|
23
|
+
return _useSWR(path,{
|
24
|
+
checkOnline : !isLocalHost,
|
25
|
+
...Object.assign({},options),
|
26
|
+
swrOptions : {
|
27
|
+
provider: () => new Map(),
|
28
|
+
...swrConfig,
|
29
|
+
isOnline() {
|
30
|
+
if(isLocalHost) return true;
|
31
|
+
return swrConfig.isOnline();
|
32
|
+
},
|
33
|
+
initReconnect(cb) {
|
34
|
+
if(isLocalHost) return cb();
|
35
|
+
return swrConfig.initReconnect(cb);
|
36
|
+
},
|
37
|
+
...extendObj({},options,options?.swrOptions)
|
38
|
+
}
|
39
|
+
})
|
40
|
+
}
|
41
|
+
|
42
|
+
|
20
43
|
/**** retourne un composant définit dans la props
|
21
44
|
components de la fonction registerApp appelée pour l'initialisation de l'application
|
22
45
|
@param {string} componentName : le nom du composant que l'on veut recupérer
|