mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-16 08:51:40 +08:00
chore: Update switchVersion and switchVersionLater to be async functions
This commit is contained in:
@@ -126,7 +126,7 @@ export class Pushy {
|
||||
PushyModule.markSuccess();
|
||||
this.report({ type: 'markSuccess' });
|
||||
};
|
||||
switchVersion = (hash: string) => {
|
||||
switchVersion = async (hash: string) => {
|
||||
if (__DEV__) {
|
||||
console.warn(
|
||||
'您调用了switchVersion方法,但是当前是开发环境,不会进行任何操作。',
|
||||
@@ -136,11 +136,11 @@ export class Pushy {
|
||||
if (this.assertHash(hash) && !this.applyingUpdate) {
|
||||
log('switchVersion: ' + hash);
|
||||
this.applyingUpdate = true;
|
||||
PushyModule.reloadUpdate({ hash });
|
||||
return PushyModule.reloadUpdate({ hash });
|
||||
}
|
||||
};
|
||||
|
||||
switchVersionLater = (hash: string) => {
|
||||
switchVersionLater = async (hash: string) => {
|
||||
if (__DEV__) {
|
||||
console.warn(
|
||||
'您调用了switchVersionLater方法,但是当前是开发环境,不会进行任何操作。',
|
||||
@@ -149,7 +149,7 @@ export class Pushy {
|
||||
}
|
||||
if (this.assertHash(hash)) {
|
||||
log('switchVersionLater: ' + hash);
|
||||
PushyModule.setNeedUpdate({ hash });
|
||||
return PushyModule.setNeedUpdate({ hash });
|
||||
}
|
||||
};
|
||||
checkUpdate = async (extra?: Record<string, any>) => {
|
||||
|
@@ -7,8 +7,8 @@ const asyncNoop = () => Promise.resolve();
|
||||
|
||||
export const defaultContext = {
|
||||
checkUpdate: asyncNoop,
|
||||
switchVersion: noop,
|
||||
switchVersionLater: noop,
|
||||
switchVersion: asyncNoop,
|
||||
switchVersionLater: asyncNoop,
|
||||
markSuccess: noop,
|
||||
dismissError: noop,
|
||||
downloadUpdate: asyncNoop,
|
||||
@@ -21,8 +21,8 @@ export const defaultContext = {
|
||||
|
||||
export const PushyContext = createContext<{
|
||||
checkUpdate: () => Promise<void>;
|
||||
switchVersion: () => void;
|
||||
switchVersionLater: () => void;
|
||||
switchVersion: () => Promise<void>;
|
||||
switchVersionLater: () => Promise<void>;
|
||||
markSuccess: () => void;
|
||||
dismissError: () => void;
|
||||
downloadUpdate: () => Promise<void>;
|
||||
|
@@ -73,18 +73,18 @@ export const PushyProvider = ({
|
||||
);
|
||||
|
||||
const switchVersion = useCallback(
|
||||
(info: CheckResult | undefined = updateInfoRef.current) => {
|
||||
async (info: CheckResult | undefined = updateInfoRef.current) => {
|
||||
if (info && info.hash) {
|
||||
client.switchVersion(info.hash);
|
||||
return client.switchVersion(info.hash);
|
||||
}
|
||||
},
|
||||
[client],
|
||||
);
|
||||
|
||||
const switchVersionLater = useCallback(
|
||||
(info: CheckResult | undefined = updateInfoRef.current) => {
|
||||
async (info: CheckResult | undefined = updateInfoRef.current) => {
|
||||
if (info && info.hash) {
|
||||
client.switchVersionLater(info.hash);
|
||||
return client.switchVersionLater(info.hash);
|
||||
}
|
||||
},
|
||||
[client],
|
||||
|
Reference in New Issue
Block a user