withHook

suspend fun <T> withHook(action: suspend (EntityChange) -> Unit, body: suspend () -> T): T

Calls the specified body with the given state-change action, registers the action, and returns its result.

The action will be unregistered at the end of the call to the body block.