<commit_before># Mobx-State-Tree API reference guide

_This reference guide lists all methods exposed by MST. Contributions like linguistic improvements, adding more details to the descriptions or additional examples are highly appreciated! Please note that the docs are generated from source. Most methods are declared in the [mst-operations.ts](https://github.com/mobxjs/mobx-state-tree/blob/master/src/core/mst-operations.ts) file._

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

-   [addDisposer](#adddisposer)
-   [addMiddleware](#addmiddleware)
-   [applyAction](#applyaction)
-   [applyPatch](#applypatch)
-   [applySnapshot](#applysnapshot)
-   [BaseReferenceType](#basereferencetype)
-   [BaseReferenceType](#basereferencetype-1)
-   [cast](#cast)
-   [clone](#clone)
-   [ComplexType](#complextype)
-   [ComplexType](#complextype-1)
-   [ComplexType](#complextype-2)
-   [ComplexType](#complextype-3)
-   [ComplexType](#complextype-4)
-   [createActionTrackingMiddleware](#createactiontrackingmiddleware)
-   [decorate](#decorate)
-   [destroy](#destroy)
-   [detach](#detach)
-   [escapeJsonPath](#escapejsonpath)
-   [flow](#flow)
-   [getChildType](#getchildtype)
-   [getEnv](#getenv)
-   [getIdentifier](#getidentifier)
-   [getMembers](#getmembers)
-   [getParent](#getparent)
-   [getParentOfType](#getparentoftype)
-   [getPath](#getpath)
-   [getPathParts](#getpathparts)
-   [getRelativePath](#getrelativepath)
-   [getRoot](#getroot)
-   [getSnapshot](#getsnapshot)
-   [getType](#gettype)
-   [hasParent](#hasparent)
-   [hasParentOfType](#hasparentoftype)
-   [IdentifierCache](#identifiercache)
-   [IdentifierType](#identifiertype)
-   [isAlive](#isalive)
-   [isProtected](#isprotected)
-   [isRoot](#isroot)
-   [isStateTreeNode](#isstatetreenode)
-   [joinJsonPath](#joinjsonpath)
-   [ObjectNode](#objectnode)
-   [ObservableMap](#observablemap)
-   [onAction](#onaction)
-   [onPatch](#onpatch)
-   [onSnapshot](#onsnapshot)
-   [process](#process)
-   [protect](#protect)
-   [recordActions](#recordactions)
-   [recordPatches](#recordpatches)
-   [resolveIdentifier](#resolveidentifier)
-   [resolvePath](#resolvepath)
-   [ScalarNode](#scalarnode)
-   [setLivelynessChecking](#setlivelynesschecking)
-   [splitJsonPath](#splitjsonpath)
-   [StoredReference](#storedreference)
-   [tryResolve](#tryresolve)
-   [Type](#type)
-   [Type](#type-1)
-   [Type](#type-2)
-   [Type](#type-3)
-   [Type](#type-4)
-   [Type](#type-5)
-   [Type](#type-6)
-   [Type](#type-7)
-   [Type](#type-8)
-   [Type](#type-9)
-   [typecheck](#typecheck)
-   [types.array](#typesarray)
-   [types.boolean](#typesboolean)
-   [types.compose](#typescompose)
-   [types.custom](#typescustom)
-   [types.Date](#typesdate)
-   [types.enumeration](#typesenumeration)
-   [types.frozen](#typesfrozen)
-   [types.identifier](#typesidentifier)
-   [types.identifierNumber](#typesidentifiernumber)
-   [types.integer](#typesinteger)
-   [types.late](#typeslate)
-   [types.literal](#typesliteral)
-   [types.map](#typesmap)
-   [types.maybe](#typesmaybe)
-   [types.maybeNull](#typesmaybenull)
-   [types.model](#typesmodel)
-   [types.null](#typesnull)
-   [types.number](#typesnumber)
-   [types.optional](#typesoptional)
-   [types.reference](#typesreference)
-   [types.refinement](#typesrefinement)
-   [types.string](#typesstring)
-   [types.undefined](#typesundefined)
-   [types.union](#typesunion)
-   [unescapeJsonPath](#unescapejsonpath)
-   [unprotect](#unprotect)
-   [walk](#walk)

## addDisposer

Use this utility to register a function that should be called whenever the
targeted state tree node is destroyed. This is a useful alternative to managing
cleanup methods yourself using the `beforeDestroy` hook.

**Parameters**

-   `target` **IStateTreeNode** 
-   `disposer`  

**Examples**

```javascript
const Todo = types.model({
  title: types.string
}).actions(self => ({
  afterCreate() {
    const autoSaveDisposer = reaction(
      () => getSnapshot(self),
      snapshot => sendSnapshotToServerSomehow(snapshot)
    )
    // stop sending updates to server if this
    // instance is destroyed
    addDisposer(self, autoSaveDisposer)
  }
}))
```

## addMiddleware

Middleware can be used to intercept any action is invoked on the subtree where it is attached.
If a tree is protected (by default), this means that any mutation of the tree will pass through your middleware.

For more details, see the [middleware docs](docs/middleware.md)

**Parameters**

-   `target` **IStateTreeNode** 
-   `handler`  
-   `includeHooks`  

Returns **IDisposer** 

## applyAction

Applies an action or a series of actions in a single MobX transaction.
Does not return any value
Takes an action description as produced by the `onAction` middleware.

**Parameters**

-   `target` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
-   `actions` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;IActionCall>** 

## applyPatch

Applies a JSON-patch to the given model instance or bails out if the patch couldn't be applied
See [patches](https://github.com/mobxjs/mobx-state-tree#patches) for more details.

Can apply a single past, or an array of patches.

**Parameters**

-   `target` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
-   `patch` **IJsonPatch** 

## applySnapshot

Applies a snapshot to a given model instances. Patch and snapshot listeners will be invoked as usual.

**Parameters**

-   `target` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
-   `snapshot` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

## BaseReferenceType

## BaseReferenceType

## cast

Casts a node snapshot or instance type to an instance type so it can be assigned to a type instance.
Note that this is just a cast for the type system, this is, it won't actually convert a snapshot to an instance,
but just fool typescript into thinking so.
Casting only works on assignation operations, it won't work (compile) stand-alone.
Technically it is not required for instances, but it is provided for consistency reasons.

**Parameters**

-   `snapshotOrInstance` **CastedType&lt;T>** 

**Examples**

```javascript
const ModelA = types.model({
  n: types.number
}).actions(self => ({
  setN(aNumber: number) {
    self.n = aNumber
  }
}))

const ModelB = types.model({
  innerModel: ModelA
}).actions(self => ({
  someAction() {
    // this will allow the compiler to assign an snapshot to the property
    self.innerModel = cast({ a: 5 })
  }
}))
```

Returns **T** 

## clone
<commit_msg>Rebuilt docs<commit_after># Mobx-State-Tree API reference guide

_This reference guide lists all methods exposed by MST. Contributions like linguistic improvements, adding more details to the descriptions or additional examples are highly appreciated! Please note that the docs are generated from source. Most methods are declared in the [mst-operations.ts](https://github.com/mobxjs/mobx-state-tree/blob/master/src/core/mst-operations.ts) file._

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

-   [addDisposer](#adddisposer)
-   [addMiddleware](#addmiddleware)
-   [applyAction](#applyaction)
-   [applyPatch](#applypatch)
-   [applySnapshot](#applysnapshot)
-   [BaseReferenceType](#basereferencetype)
-   [BaseReferenceType](#basereferencetype-1)
-   [cast](#cast)
-   [clone](#clone)
-   [ComplexType](#complextype)
-   [ComplexType](#complextype-1)
-   [ComplexType](#complextype-2)
-   [ComplexType](#complextype-3)
-   [ComplexType](#complextype-4)
-   [createActionTrackingMiddleware](#createactiontrackingmiddleware)
-   [decorate](#decorate)
-   [destroy](#destroy)
-   [detach](#detach)
-   [escapeJsonPath](#escapejsonpath)
-   [flow](#flow)
-   [getChildType](#getchildtype)
-   [getEnv](#getenv)
-   [getIdentifier](#getidentifier)
-   [getMembers](#getmembers)
-   [getParent](#getparent)
-   [getParentOfType](#getparentoftype)
-   [getPath](#getpath)
-   [getPathParts](#getpathparts)
-   [getRelativePath](#getrelativepath)
-   [getRoot](#getroot)
-   [getSnapshot](#getsnapshot)
-   [getType](#gettype)
-   [hasParent](#hasparent)
-   [hasParentOfType](#hasparentoftype)
-   [IdentifierCache](#identifiercache)
-   [IdentifierType](#identifiertype)
-   [isAlive](#isalive)
-   [isProtected](#isprotected)
-   [isRoot](#isroot)
-   [isStateTreeNode](#isstatetreenode)
-   [joinJsonPath](#joinjsonpath)
-   [ObjectNode](#objectnode)
-   [ObservableMap](#observablemap)
-   [onAction](#onaction)
-   [onPatch](#onpatch)
-   [onSnapshot](#onsnapshot)
-   [process](#process)
-   [protect](#protect)
-   [recordActions](#recordactions)
-   [recordPatches](#recordpatches)
-   [resolveIdentifier](#resolveidentifier)
-   [resolvePath](#resolvepath)
-   [ScalarNode](#scalarnode)
-   [setLivelynessChecking](#setlivelynesschecking)
-   [splitJsonPath](#splitjsonpath)
-   [StoredReference](#storedreference)
-   [tryResolve](#tryresolve)
-   [Type](#type)
-   [Type](#type-1)
-   [Type](#type-2)
-   [Type](#type-3)
-   [Type](#type-4)
-   [Type](#type-5)
-   [Type](#type-6)
-   [Type](#type-7)
-   [Type](#type-8)
-   [Type](#type-9)
-   [typecheck](#typecheck)
-   [types.array](#typesarray)
-   [types.boolean](#typesboolean)
-   [types.compose](#typescompose)
-   [types.custom](#typescustom)
-   [types.Date](#typesdate)
-   [types.enumeration](#typesenumeration)
-   [types.frozen](#typesfrozen)
-   [types.identifier](#typesidentifier)
-   [types.identifierNumber](#typesidentifiernumber)
-   [types.integer](#typesinteger)
-   [types.late](#typeslate)
-   [types.literal](#typesliteral)
-   [types.map](#typesmap)
-   [types.maybe](#typesmaybe)
-   [types.maybeNull](#typesmaybenull)
-   [types.model](#typesmodel)
-   [types.null](#typesnull)
-   [types.number](#typesnumber)
-   [types.optional](#typesoptional)
-   [types.reference](#typesreference)
-   [types.refinement](#typesrefinement)
-   [types.string](#typesstring)
-   [types.undefined](#typesundefined)
-   [types.union](#typesunion)
-   [unescapeJsonPath](#unescapejsonpath)
-   [unprotect](#unprotect)
-   [walk](#walk)

## addDisposer

Use this utility to register a function that should be called whenever the
targeted state tree node is destroyed. This is a useful alternative to managing
cleanup methods yourself using the `beforeDestroy` hook.

**Parameters**

-   `target` **IStateTreeNode** 
-   `disposer`  

**Examples**

```javascript
const Todo = types.model({
  title: types.string
}).actions(self => ({
  afterCreate() {
    const autoSaveDisposer = reaction(
      () => getSnapshot(self),
      snapshot => sendSnapshotToServerSomehow(snapshot)
    )
    // stop sending updates to server if this
    // instance is destroyed
    addDisposer(self, autoSaveDisposer)
  }
}))
```

## addMiddleware

Middleware can be used to intercept any action is invoked on the subtree where it is attached.
If a tree is protected (by default), this means that any mutation of the tree will pass through your middleware.

For more details, see the [middleware docs](docs/middleware.md)

**Parameters**

-   `target` **IStateTreeNode** 
-   `handler`  
-   `includeHooks`  

Returns **IDisposer** 

## applyAction

Applies an action or a series of actions in a single MobX transaction.
Does not return any value
Takes an action description as produced by the `onAction` middleware.

**Parameters**

-   `target` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
-   `actions` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;IActionCall>** 

## applyPatch

Applies a JSON-patch to the given model instance or bails out if the patch couldn't be applied
See [patches](https://github.com/mobxjs/mobx-state-tree#patches) for more details.

Can apply a single past, or an array of patches.

**Parameters**

-   `target` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
-   `patch` **IJsonPatch** 

## applySnapshot

Applies a snapshot to a given model instances. Patch and snapshot listeners will be invoked as usual.

**Parameters**

-   `target` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
-   `snapshot` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

## BaseReferenceType

## BaseReferenceType

## cast

Casts a node snapshot or instance type to an instance type so it can be assigned to a type instance.
Alternatively also casts a node snapshot or instance to an snapshot type so it can be assigned to a type snapshot.
Note that this is just a cast for the type system, this is, it won't actually convert a snapshot to an instance
(or vice-versa), but just fool typescript into thinking so.
Casting only works on assignation operations, it won't work (compile) stand-alone.

**Parameters**

-   `snapshotOrInstance` **CastedType&lt;T>** 

**Examples**

```javascript
const ModelA = types.model({
  n: types.number
}).actions(self => ({
  setN(aNumber: number) {
    self.n = aNumber
  }
}))

const ModelB = types.model({
  innerModel: ModelA
}).actions(self => ({
  someAction() {
    // this will allow the compiler to assign an snapshot to the property
    self.innerModel = cast({ a: 5 })
  }
}))
```

Returns **T** 

## clone

{'fraction_non_alphanumeric': 0.1514398479754422, 'fraction_numerical': 0.002192661891536325, 'mean_word_length': 4.477582065652522, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 14, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2568684', 'n_tokens_mistral': 4566, 'n_tokens_neox': 4263, 'n_words': 982}