UNPKG

mobx-keystone

Version:

A MobX powered state management solution based on data trees with first class support for TypeScript, snapshots, patches and much more

34 lines (29 loc) 948 B
import { remove } from "mobx" import { assertTweakedObject } from "../tweaker/core" import { lazy } from "../utils" import { BuiltInAction } from "./builtInActions" import { ActionContextActionType } from "./context" import { wrapInAction } from "./wrapInAction" /** * Deletes an object field wrapped in an action. * * @param node Target object. * @param fieldName Field name. */ export function applyDelete<O extends object, K extends keyof O>(node: O, fieldName: K): void { assertTweakedObject(node, "node", true) wrappedInternalApplyDelete().call(node, fieldName as string | number) } /** * @internal */ export function internalApplyDelete<O extends object>(this: O, fieldName: string | number): void { remove(this, String(fieldName)) } const wrappedInternalApplyDelete = lazy(() => wrapInAction({ nameOrNameFn: BuiltInAction.ApplyDelete, fn: internalApplyDelete, actionType: ActionContextActionType.Sync, }) )