Skip to content

Commit

Permalink
Avoid use of restate context in payment example
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkleeman committed Oct 8, 2024
1 parent 92935eb commit 0c773d6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"plugins": ["@typescript-eslint", "require-extensions"],
"rules": {
"no-console": "error",
"no-console": "off",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/restrict-template-expressions": [
Expand Down
16 changes: 4 additions & 12 deletions examples/payment/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const machine = setup({
amount: number;
},
input: {} as {
ctx: restate.ObjectContext;
key: string; // the key the state machine was created against
senderUserID: string;
recipientUserID: string;
amount: number;
Expand All @@ -26,16 +26,8 @@ export const machine = setup({
},
actors: {
updateBalance: fromPromise(
async ({
input,
ctx,
}: {
input: { userID: string; amount: number };
ctx: restate.ObjectSharedContext;
}) => {
ctx.console.log(
`Adding ${input.amount} to the balance of ${input.userID}`
);
async ({ input }: { input: { userID: string; amount: number } }) => {
console.log(`Adding ${input.amount} to the balance of ${input.userID}`);
const res = await fetch("https://httpbin.org/get");
return res.json();
}
Expand All @@ -46,7 +38,7 @@ export const machine = setup({
senderUserID: input.senderUserID,
recipientUserID: input.recipientUserID,
amount: input.amount,
paymentID: input.ctx.key,
paymentID: input.key,
}),
id: "Payment",
initial: "Awaiting approval",
Expand Down
1 change: 1 addition & 0 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ const actorObject = <TLogic extends AnyStateMachine>(
await createActor(ctx, api, systemName, logic, {
input: {
ctx,
key: ctx.key,
...(request?.input ?? {}),
} as InputFrom<TLogic>,
})
Expand Down

0 comments on commit 0c773d6

Please sign in to comment.