MCPcopy Index your code
hub / github.com/reactnativecn/react-native-update / UpdateProvider

Function UpdateProvider

src/provider.tsx:32–404  ·  view source on GitHub ↗
({
  client,
  children,
}: {
  client: Pushy | Cresc;
  children: ReactNode;
})

Source from the content-addressed store, hash-verified

30import { assertWeb, log } from './utils';
31
32export const UpdateProvider = ({
33 client,
34 children,
35}: {
36 client: Pushy | Cresc;
37 children: ReactNode;
38}) => {
39 client = useRef(client).current;
40 const { options } = client;
41
42 const stateListener = useRef<NativeEventSubscription>(undefined);
43 const [updateInfo, setUpdateInfo] = useState<CheckResult>();
44 const updateInfoRef = useRef(updateInfo);
45 const [progress, setProgress] = useState<ProgressData>();
46 const [lastError, setLastError] = useState<Error>();
47 const lastChecking = useRef(0);
48
49 const throwErrorIfEnabled = useCallback(
50 (e: Error) => {
51 if (options.throwError) {
52 throw e;
53 }
54 },
55 [options.throwError],
56 );
57
58 const dismissError = useCallback(() => {
59 setLastError(undefined);
60 }, []);
61
62 const alertUpdate = useCallback(
63 (...args: Parameters<typeof Alert.alert>) => {
64 if (
65 options.updateStrategy === 'alwaysAlert' ||
66 options.updateStrategy === 'alertUpdateAndIgnoreError'
67 ) {
68 Alert.alert(...args);
69 }
70 },
71 [options.updateStrategy],
72 );
73
74 const alertError = useCallback(
75 (...args: Parameters<typeof Alert.alert>) => {
76 if (options.updateStrategy === 'alwaysAlert') {
77 Alert.alert(...args);
78 }
79 },
80 [options.updateStrategy],
81 );
82
83 const switchVersion = useCallback(
84 async (info: CheckResult | undefined = updateInfoRef.current) => {
85 if (info && info.hash) {
86 return client.switchVersion(info.hash);
87 }
88 },
89 [client],

Callers

nothing calls this directly

Calls 7

logFunction · 0.90
resolveCheckResultFunction · 0.90
assertWebFunction · 0.90
tMethod · 0.80
downloadAndInstallApkMethod · 0.65
restartAppMethod · 0.65
switchVersionMethod · 0.45

Tested by

no test coverage detected