Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to have props to initialize component in getServerState #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/lib/getServerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ export const getServerContext = () =>

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getServerState(component: any, serverUrl: URL): Promise<Record<string, any>> {
return getServerStateWithProps(component, serverUrl, {});
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getServerStateWithProps(component: any, serverUrl: URL, props: any): Promise<Record<string, any>> {
return new Promise((resolve) => {
const notifyServer = async (search: InstantSearch) => {
await waitForResults(search);
const results = getInitialResults(search.mainIndex);
search.dispose();
resolve(results);
};
component.render({}, { context: new Map([[serverContext, { notifyServer, serverUrl }]]) });
component.render(props, { context: new Map([[serverContext, { notifyServer, serverUrl }]]) });
});
}

2 changes: 1 addition & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { default as InstantSearch } from "./InstantSearch.svelte";
export { default as connect } from "./connect";
export { getInstantSearchContext } from "./instantSearchContext";
export { getServerState } from "./getServerState";
export { getServerState, getServerStateWithProps } from "./getServerState";
export * from "./widgets";