Commands - worldscapes/engine GitHub Wiki

Command is structure that contains name of action that should be executed and data needed for it.

They are used in layers so pure functions can describe side-effect that should be created after their execution. This way we still keep them pure.

Sometimes Commands can depend on handler execution result of other Command. In this case handler should generate more Commands using result. Also, it allows CommandHandler composition and better reusability.

If Command needs some already exisitng Store state, this state can be passed to Command body if available for Command creator, or Command handler can use synchronous Store Queries to receive needed state at handling time.

Since Commands can be passed to client (to optimize change detection in simulation layer), they should not be checked by class and should have type field.

Commands which WRITE to the store should be marked explicitly to avoid parallelisation problems. Their handlers will recieved ReadonlyStore object.