import { inject } from 'mobx-react' ; import { AppViewModel } from '.' ; type KeyOfAVM = AppViewModel [ keyof AppViewModel ] ; export type ViewModelInjector = ( viewModel : AppViewModel ) => KeyOfAVM ; export type ViewModelInjectorMulti = ( viewModel : AppViewModel ) => { [ key ] : KeyOfAVM ; } ; export type ViewModelPartial < T extends KeyOfAVM > = { model ? : T ; } ; const getViewModel = ( inner ) => { return ( store ) => ( { model : store && store . viewModel && inner ( store . viewModel ) , } ) ; } ; const getViewModelMulti = ( inner ) => { return ( store ) => ( { ... ( store && store . viewModel && inner ( store . viewModel ) ) , } ) ; } ; export function injectViewModel ( inner ) { return inject ( getViewModel ( inner ) ) ; } export function injectViewModelsMulti ( inner ) { return inject ( getViewModelMulti ( inner ) ) ; }