mobx-keystone-mindreframer
Version:
A MobX powered state management solution based on data trees with first class support for Typescript, snapshots, patches and much more
45 lines (39 loc) • 792 B
text/typescript
import { failure } from "../utils"
import { getCurrentActionContext } from "./context"
/**
* @ignore
* @internal
*/
export function canWrite(): boolean {
return !getActionProtection() || !!getCurrentActionContext()
}
/**
* @ignore
* @internal
*/
export function assertCanWrite() {
if (!canWrite()) {
throw failure("data changes must be performed inside model actions")
}
}
let actionProtection = true
/**
* @ignore
* @internal
*
* Gets if the action protection is currently enabled or not.
*
* @returns
*/
export function getActionProtection() {
return actionProtection
}
/**
* @ignore
* @internal
*
* Sets if the action protection is currently enabled or not.
*/
export function setActionProtection(protection: boolean) {
actionProtection = protection
}