feat(Tabbar): add before-change prop (#7081)

This commit is contained in:
neverland
2020-09-02 11:45:11 +08:00
committed by GitHub
parent b276fb5a78
commit d55585314f
5 changed files with 90 additions and 3 deletions
+27
View File
@@ -0,0 +1,27 @@
import { isPromise, noop } from '.';
export function callInterceptor(options: {
interceptor?: (...args: any[]) => Promise<boolean> | boolean;
done: () => void;
args: any[];
}) {
const { interceptor, args, done } = options;
if (interceptor) {
const returnVal = interceptor(...args);
if (isPromise(returnVal)) {
returnVal
.then((value) => {
if (value) {
done();
}
})
.catch(noop);
} else if (returnVal) {
done();
}
} else {
done();
}
}