Skip to content

Commit

Permalink
pass simulationStore directly to handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
jbolda committed Jun 1, 2024
1 parent 5b4c890 commit 367b08a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
12 changes: 3 additions & 9 deletions packages/foundation/example/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,14 @@ startServerStandalone({
openapiSchemaFromRealEndpoint,
openapiSchemaWithModificationsForSimulation,
],
handlers({ simulationStore }) {
handlers({ store, schema, actions }) {
return {
getDogs: (c, req, res) => {
let dogs = simulationStore.schema.boop.select(
simulationStore.store.getState()
);
let dogs = schema.boop.select(store.getState());
res.status(200).json({ dogs });
},
putDogs: (c, req, res) => {
simulationStore.store.dispatch(
simulationStore.actions.updater(
simulationStore.schema.boop.increment()
)
);
store.dispatch(actions.updater(schema.boop.increment()));
res.sendStatus(200);
},
};
Expand Down
10 changes: 4 additions & 6 deletions packages/foundation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ export async function startServerStandalone<
}: {
openapi?: {
document: Document | [Document, RecursivePartial<Document>];
handlers: ({
simulationStore,
}: {
simulationStore: SimulationStoreContext;
}) => Record<string, Handler | Record<string, Handler>>;
handlers: (
simulationStore: SimulationStoreContext
) => Record<string, Handler | Record<string, Handler>>;
apiRoot?: string;
};
port: number;
Expand Down Expand Up @@ -74,7 +72,7 @@ export async function startServerStandalone<
}
}
};
handlerObjectRegistration(handlers({ simulationStore }));
handlerObjectRegistration(handlers(simulationStore));

api.register({
validationFail: (c, req, res) =>
Expand Down

0 comments on commit 367b08a

Please sign in to comment.