1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-09-16 10:31:39 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

chore: Update switchVersion and switchVersionLater to be async functions

This commit is contained in:
sunnylqm
2024-08-16 10:48:39 +08:00
parent 6d980a4c04
commit 10178e1e64
3 changed files with 12 additions and 12 deletions

View File

@@ -126,7 +126,7 @@ export class Pushy {
PushyModule.markSuccess(); PushyModule.markSuccess();
this.report({ type: 'markSuccess' }); this.report({ type: 'markSuccess' });
}; };
switchVersion = (hash: string) => { switchVersion = async (hash: string) => {
if (__DEV__) { if (__DEV__) {
console.warn( console.warn(
'您调用了switchVersion方法但是当前是开发环境不会进行任何操作。', '您调用了switchVersion方法但是当前是开发环境不会进行任何操作。',
@@ -136,11 +136,11 @@ export class Pushy {
if (this.assertHash(hash) && !this.applyingUpdate) { if (this.assertHash(hash) && !this.applyingUpdate) {
log('switchVersion: ' + hash); log('switchVersion: ' + hash);
this.applyingUpdate = true; this.applyingUpdate = true;
PushyModule.reloadUpdate({ hash }); return PushyModule.reloadUpdate({ hash });
} }
}; };
switchVersionLater = (hash: string) => { switchVersionLater = async (hash: string) => {
if (__DEV__) { if (__DEV__) {
console.warn( console.warn(
'您调用了switchVersionLater方法但是当前是开发环境不会进行任何操作。', '您调用了switchVersionLater方法但是当前是开发环境不会进行任何操作。',
@@ -149,7 +149,7 @@ export class Pushy {
} }
if (this.assertHash(hash)) { if (this.assertHash(hash)) {
log('switchVersionLater: ' + hash); log('switchVersionLater: ' + hash);
PushyModule.setNeedUpdate({ hash }); return PushyModule.setNeedUpdate({ hash });
} }
}; };
checkUpdate = async (extra?: Record<string, any>) => { checkUpdate = async (extra?: Record<string, any>) => {

View File

@@ -7,8 +7,8 @@ const asyncNoop = () => Promise.resolve();
export const defaultContext = { export const defaultContext = {
checkUpdate: asyncNoop, checkUpdate: asyncNoop,
switchVersion: noop, switchVersion: asyncNoop,
switchVersionLater: noop, switchVersionLater: asyncNoop,
markSuccess: noop, markSuccess: noop,
dismissError: noop, dismissError: noop,
downloadUpdate: asyncNoop, downloadUpdate: asyncNoop,
@@ -21,8 +21,8 @@ export const defaultContext = {
export const PushyContext = createContext<{ export const PushyContext = createContext<{
checkUpdate: () => Promise<void>; checkUpdate: () => Promise<void>;
switchVersion: () => void; switchVersion: () => Promise<void>;
switchVersionLater: () => void; switchVersionLater: () => Promise<void>;
markSuccess: () => void; markSuccess: () => void;
dismissError: () => void; dismissError: () => void;
downloadUpdate: () => Promise<void>; downloadUpdate: () => Promise<void>;

View File

@@ -73,18 +73,18 @@ export const PushyProvider = ({
); );
const switchVersion = useCallback( const switchVersion = useCallback(
(info: CheckResult | undefined = updateInfoRef.current) => { async (info: CheckResult | undefined = updateInfoRef.current) => {
if (info && info.hash) { if (info && info.hash) {
client.switchVersion(info.hash); return client.switchVersion(info.hash);
} }
}, },
[client], [client],
); );
const switchVersionLater = useCallback( const switchVersionLater = useCallback(
(info: CheckResult | undefined = updateInfoRef.current) => { async (info: CheckResult | undefined = updateInfoRef.current) => {
if (info && info.hash) { if (info && info.hash) {
client.switchVersionLater(info.hash); return client.switchVersionLater(info.hash);
} }
}, },
[client], [client],