Create an async thunk
export const initNotes = createAsyncThunk(
"engine/init",
async ({ port, ws }: { port: number; ws: string }, { dispatch }) => {
const logger = createLogger("initNotesThunk");
const endpoint = `http://localhost:${port}`;
logger.info({ state: "enter", endpoint, port, ws });
const api = new DendronApiV2({
endpoint,
apiPath: "api",
logger,
});
logger.info({ state: "pre:workspaceSync" });
const resp = await api.workspaceSync({ ws });
logger.info({ state: "post:workspaceSync" });
if (resp.error) {
dispatch(setError(stringifyError(resp.error)));
return resp;
}
const data = resp.data!;
logger.info({ state: "pre:setNotes" });
dispatch(setFromInit(data));
logger.info({ state: "post:setNotes" });
return resp;
}
);