kalix-javascript-sdk
kalix-javascript-sdk copied to clipboard
Generated event-sources entity JS files pass redundant state parameter
Here is an example:
entity.setInitial(entityId => ({}));
entity.setBehavior(state => ({
commandHandlers: {
AddItem(command, state, ctx) {
return ctx.fail("The command handler for `AddItem` is not implemented, yet");
},
Note that state
is a parameter in setBehavior(state => ({
and each of the command handler functions are also called with state AddItem(command, state, ctx) {
.
The state in the behaviour callback is for switching behaviour based on state, while the handler functions could be defined separately and will still want to receive the state as well. As the state machine approach is not expected to be used initially from the generated code, the codegen could instead leave out the state parameter there and generate:
entity.setBehavior(() => ({
commandHandlers: {
AddItem(command, state, ctx) {
return ctx.fail("The command handler for `AddItem` is not implemented, yet");
},
...
Also discussion on whether to keep behaviours, or make it more optional, in #334. Where there could be setCommandHandlers
and setEventHandlers
as well, to create default behaviour, if multi-behaviour / state machine approach is not being used.