-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ 修复 InputNumber 在设置为 allow-null 时被赋值为空时未触发更新的问题并支持异步更新 (#812)
- Loading branch information
1 parent
583acc2
commit 0fc90dd
Showing
5 changed files
with
173 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/uni_modules/wot-design-uni/components/common/interceptor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { isPromise } from './util' | ||
|
||
function noop() {} | ||
|
||
export type Interceptor = (...args: any[]) => Promise<boolean> | boolean | undefined | void | ||
|
||
export function callInterceptor( | ||
interceptor: Interceptor | undefined, | ||
{ | ||
args = [], | ||
done, | ||
canceled, | ||
error | ||
}: { | ||
args?: unknown[] | ||
done: () => void | ||
canceled?: () => void | ||
error?: () => void | ||
} | ||
) { | ||
if (interceptor) { | ||
// eslint-disable-next-line prefer-spread | ||
const returnVal = interceptor.apply(null, args) | ||
|
||
if (isPromise(returnVal)) { | ||
returnVal | ||
.then((value) => { | ||
if (value) { | ||
done() | ||
} else if (canceled) { | ||
canceled() | ||
} | ||
}) | ||
.catch(error || noop) | ||
} else if (returnVal) { | ||
done() | ||
} else if (canceled) { | ||
canceled() | ||
} | ||
} else { | ||
done() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.