import { ipcRenderer } from 'electron' ; const curDepIndexMap = { install : 'curInstallDepIndex' , update : 'curUpdateDepIndex' , reinstall : 'curReinstallDepIndex' , uninstall : 'curUninstallDepIndex' , } ; const defaultProcess = { percent : 0 , message : '' , status : '' , } ; export default { state : { npmDependencies : [ ] , curInstallDepIndex : [ ] , curUpdateDepIndex : [ ] , curReinstallDepIndex : [ ] , curUninstallDepIndex : [ ] , searchValue : '' , queryNpmDependencies : [ ] , globalDependenciesInfo : { recommendedPath : '' , currentPath : '' , exists : false , } , customGlobalDepsDialogVisible : false , customGlobalDepsProcess : defaultProcess , } , reducers : { addCurDepIndex ( prevState , { type , index } ) { prevState [ curDepIndexMap [ type ] ] . push ( index ) ; } , removeCurDepIndex ( prevState , { type , index } ) { const depIndex = prevState [ curDepIndexMap [ type ] ] . findIndex ( ( i ) => i === index ) ; prevState [ curDepIndexMap [ type ] ] . splice ( depIndex , 1 ) ; } , updateSearchValue ( prevState , searchValue ) { prevState . searchValue = searchValue ; } , setCustomGlobalDepsDialogVisible ( prevState , visible ) { prevState . customGlobalDepsDialogVisible = visible ; } , setCustomGlobalDepsProcess ( prevState , data ) { prevState . customGlobalDepsProcess = data ; } , initCustomGlobalDepsProcess ( prevState ) { prevState . customGlobalDepsProcess = defaultProcess ; } , } , effects : ( ) => ( { async getGlobalNpmDependencies ( force = false ) { const npmDependencies = await ipcRenderer . invoke ( 'get-global-npm-dependencies' , force ) ; this . setState ( { npmDependencies } ) ; } , async uninstallGlobalNpmDependency ( dependency ) { await ipcRenderer . invoke ( 'uninstall-global-npm-dependency' , dependency ) ; } , async updateGlobalNpmDependency ( dependency ) { await ipcRenderer . invoke ( 'update-global-npm-dependency' , dependency ) ; } , async reinstallGlobalNpmDependency ( { dependency , version } ) { await ipcRenderer . invoke ( 'reinstall-global-npm-dependency' , dependency , version ) ; } , async installGlobalNpmDependency ( { dependency , version } ) { await ipcRenderer . invoke ( 'install-global-npm-dependency' , dependency , version ) ; } , async searchNpmDependencies ( query ) { const queryNpmDependencies = await ipcRenderer . invoke ( 'search-npm-dependencies' , query ) ; this . setState ( { queryNpmDependencies } ) ; } , async getGlobalDependenciesInfo ( ) { const globalDependenciesInfo = await ipcRenderer . invoke ( 'get-global-dependencies-info' ) ; this . setState ( { globalDependenciesInfo , } ) ; } , async createCustomGlobalDepsDir ( { channel , currentGlobalDepsPath } ) { await ipcRenderer . invoke ( 'create-custom-global-dependencies-dir' , channel , currentGlobalDepsPath ) ; } , } ) , } ;