It would be interesting to have a sort of menu lifecycle hook that is triggered before this menu and any of its components (such as menu.select) are rendered. A subset of hooks such as the lifecycle hooks of Vue could be provided.
An example - assuming we had a beforeRendered hook the following would then be possible:
const menuOfTeams = new MenuTemplate(ctx => `You have ${ctx.state.teams.length} teams. Here they are:`)
menuOfTeams.chooseIntoSubmenu('details', ctx => ctx.state.teams.map(team => team.name), teamDetailsMenu)
menuOfTeams.beforeRendered(ctx => ctx.state.teams = restApi.getTeams())
The hook could easily be used to execute API calls to populate shared state, after which menu components can then access that state during rendering.
This would be more intuitive and simpler to use than configuring separate middleware. The non-lifecycle hook approach (as of today) would require something like:
bot.action(/^\/my\/relevant\/path\//, (ctx, next) => {
ctx.state.something = 'hello world!'
return next()
})
const menuTemplate = new MenuTemplate(ctx => ctx.state.something)
It would be interesting to have a sort of menu lifecycle hook that is triggered before this menu and any of its components (such as menu.select) are rendered. A subset of hooks such as the lifecycle hooks of Vue could be provided.
An example - assuming we had a
beforeRenderedhook the following would then be possible:The hook could easily be used to execute API calls to populate shared state, after which menu components can then access that state during rendering.
This would be more intuitive and simpler to use than configuring separate middleware. The non-lifecycle hook approach (as of today) would require something like: