-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(runtime-vapor): the current instance should be kept in the slot
- Loading branch information
1 parent
ba17fb9
commit 100e3fd
Showing
3 changed files
with
53 additions
and
0 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,22 @@ | ||
import { | ||
type ComponentInternalInstance, | ||
currentInstance, | ||
setCurrentInstance, | ||
} from './component' | ||
|
||
export function withCtx<T extends (...args: any) => any>( | ||
fn: T, | ||
instance: ComponentInternalInstance | null = currentInstance, | ||
): T { | ||
if (!instance) return fn | ||
|
||
const fnWithCtx = ((...args: any[]) => { | ||
const reset = setCurrentInstance(instance) | ||
try { | ||
return fn(...args) | ||
} finally { | ||
reset() | ||
} | ||
}) as T | ||
return fnWithCtx | ||
} |
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