import { Draft , Immer , IProduce } from 'immer' ; import { $O , definePrivate , isArray } from '.' ; import { commit } from '../core/commit' ; import { Observable } from '../core/Observable' ; /** Function that modifies a draft */ export type Recipe < T extends object = any , Args extends any [ ] = any [ ] , Result = any > = ( draft : Draft < T > , ... args : Args ) => Result ; export const immer = new Immer ( { onAssign ( state , prop ) { state . assigned [ prop ] = true ; } , onDelete ( state , prop ) { state . assigned [ prop ] = false ; } , onCopy ( state ) { let { base } = state ; let target = base && base [ $O ] ; if ( target ) { let { copy , assigned } = state ; if ( isArray ( base ) ) { definePrivate ( copy , $O , target ) ; } target . _rebind ( copy ) ; for ( let prop in assigned ) { commit ( target , base [ prop ] , copy [ prop ] , prop , ! assigned [ prop ] , state ) ; } commit ( target , base , copy , null , false , state ) ; } } , } ) ; export default immer . produce ; export const produce = immer . produce ; export const setAutoFreeze = immer . setAutoFreeze . bind ( immer ) ; export const setUseProxies = immer . setUseProxies . bind ( immer ) ;