-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # packages/vue/src/index.ts
- Loading branch information
Showing
3 changed files
with
26 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Ref, ref } from 'vue'; | ||
|
||
/** | ||
* Creates a ref that is populated with promise result once it's resolved. | ||
* @param promise Ref will be populated with this promise's result. | ||
*/ | ||
export function refAsync<T>(promise: Promise<T>): Ref<T | undefined>; | ||
/** | ||
* Creates a ref that is populated with promise result once it's resolved. | ||
* @param fcn Function that returns a promise. Ref will be populated with this promise's result. | ||
*/ | ||
export function refAsync<T>(fcn: () => Promise<T>): Ref<T | undefined>; | ||
export function refAsync<T>(promise: Promise<T> | (() => Promise<T>)): Ref<T | undefined> { | ||
const reference = ref<T>(); | ||
|
||
if (typeof promise === 'function') { | ||
promise = promise(); | ||
} | ||
|
||
void promise.then(result => { | ||
reference.value = result; | ||
}); | ||
|
||
return reference; | ||
} |
This file was deleted.
Oops, something went wrong.