Skip to content

Commit

Permalink
refactor(menu): inline menu body function
Browse files Browse the repository at this point in the history
  • Loading branch information
EdJoPaTo committed Mar 11, 2024
1 parent 0d5a1ed commit 4986f0f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 2 additions & 4 deletions examples/main-javascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,15 @@ function personButtonText(_, key) {
return key;
}

function foodSelectText(ctx) {
const foodSelectSubmenu = new MenuTemplate(ctx => {
const person = ctx.match[1];
const hisChoice = people[person].food;
if (!hisChoice) {
return `${person} is still unsure what to eat.`;
}

return `${person} likes ${hisChoice} currently.`;
}

const foodSelectSubmenu = new MenuTemplate(foodSelectText);
});
foodSelectSubmenu.toggle('Prefer tea', 'tea', {
set(ctx, choice) {
const person = ctx.match[1];
Expand Down
6 changes: 2 additions & 4 deletions examples/main-typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,15 @@ function personButtonText(_: MyContext, key: string): string {
return key;
}

function foodSelectText(ctx: MyContext): string {
const foodSelectSubmenu = new MenuTemplate<MyContext>(ctx => {
const person = ctx.match![1]!;
const hisChoice = people[person]!.food;
if (!hisChoice) {
return `${person} is still unsure what to eat.`;
}

return `${person} likes ${hisChoice} currently.`;
}

const foodSelectSubmenu = new MenuTemplate<MyContext>(foodSelectText);
});
foodSelectSubmenu.toggle('Prefer tea', 'tea', {
set(ctx, choice) {
const person = ctx.match![1]!;
Expand Down

0 comments on commit 4986f0f

Please sign in to comment.