Attaches an action middleware that will throw when any action is started
over the node or any of the child nodes, thus effectively making the subtree
readonly.
It will return an object with a dispose function to remove the middleware and a allowWrite function
that will allow actions to be started inside the provided code block.
Example:
// given a model instance named todo const { dispose, allowWrite } = readonlyMiddleware(todo)
// this will throw todo.setDone(false) awaittodo.setDoneAsync(false)
// this will work allowWrite(() =>todo.setDone(false)) // note: for async always use one action invocation per allowWrite! awaitallowWrite(() =>todo.setDoneAsync(false))
Attaches an action middleware that will throw when any action is started over the node or any of the child nodes, thus effectively making the subtree readonly.
It will return an object with a
dispose
function to remove the middleware and aallowWrite
function that will allow actions to be started inside the provided code block.Example: