import { createActionTrackingMiddleware2 , recordPatches , IPatchRecorder , isActionContextThisOrChildOf } from "mobx-state-tree" ; const atomic = createActionTrackingMiddleware2 < { recorder : IPatchRecorder ; } > ( { filter ( call ) { if ( call . env ) { return false ; } return true ; } , onStart ( call ) { const recorder = recordPatches ( call . tree , ( _patch , _inversePatch , actionContext ) => { return ! ! actionContext && isActionContextThisOrChildOf ( actionContext , call . id ) ; } ) ; recorder . resume ( ) ; call . env = { recorder } ; } , onFinish ( call , error ) { const recorder = call . env ! . recorder ; call . env = undefined ; recorder . stop ( ) ; if ( error !== undefined ) { recorder . undo ( ) ; } } } ) ; export default atomic ;