import { UpdateDef , UpdateResolveFn } from '../types/update' ; import { Metadata } from '../types/metadata' ; import { ensureMetadata } from './metadata' ; export function setUpdateMetadata ( proto , propName , mutation ) { const constructor = proto . constructor ; const meta = ensureMetadata ( constructor ) ; meta . updates . push ( { propName , mutation , } ) ; } export function transformUpdates ( instance , meta , transformFn = resolver => resolver ) { if ( meta . updates ) { return meta . updates . map ( ( { propName , mutation } ) => ( { mutation , resolve : transformFn ( instance [ propName ] . bind ( instance ) ) , } ) ) ; } }