-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make useConfig() work for vike-solid hooks
- Loading branch information
Showing
1 changed file
with
16 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
export async function callCumulativeHooks(values: undefined | unknown[], pageContext: unknown): Promise<unknown[]> { | ||
if (!values) return []; | ||
export { callCumulativeHooks } | ||
|
||
import { providePageContext } from 'vike/getPageContext' | ||
|
||
async function callCumulativeHooks( | ||
values: undefined | unknown[], | ||
pageContext: Record<string, any>, | ||
): Promise<unknown[]> { | ||
if (!values) return [] | ||
const valuesPromises = values.map((val) => { | ||
if (typeof val === "function") { | ||
if (typeof val === 'function') { | ||
providePageContext(pageContext) | ||
// Hook | ||
return val(pageContext); | ||
return val(pageContext) | ||
} else { | ||
// Plain value | ||
return val; | ||
return val | ||
} | ||
}); | ||
const valuesResolved = await Promise.all(valuesPromises); | ||
return valuesResolved; | ||
}) | ||
const valuesResolved = await Promise.all(valuesPromises) | ||
return valuesResolved | ||
} |