Run multiple commands in sequence

Is it possible to run multiple commands in sequence? First I thought chainCommands is the solution but this function does another job.

You can call them one after the other. Is there anything about that that is causing problems for you?

Yeah, my fault :man_facepalming::sweat_smile:

Hi guys! It does not seem to work. In my case just the last command work, because the first command creates a transaction and call dispatch() but all the following work with old transaction

Commands don’t compose like that. You can call multiple commands in order to execute them after each other. But you can’t make them combine their transactions.

You can call multiple commands in order to execute them after each other

Do you think this is possible? Commands call dispatch() inside them, so it means that we should pass another updated state into the next command. Imagine the case:

const runCommands = (state, dispatch) => {
   command1(state, dispatch);
   command2(state, dispatch); // the state here would be still
}

as the result just the command2 will be applied

another example:

const runCommands = (state, dispatch) => {
   command1(state, (tr) => {
      const newState = state.tr.apply(tr);
      command2(state, dispatch); // prosemirror throws an error here that the tr is still or mismatched
   });

The idea would be

command1(view.state, view.dispatch)
command2(view.state, view.dispatch)

Unfortunately, it does not work.

In the command1 we call dispatch(state.tr); and the command2 gets the old state.tr and call it’s own dispatch(state.tr)

I assume you meant to use newState in the 2nd line?

yes, exactly