Skip to content

Commit

Permalink
Develop (#444)
Browse files Browse the repository at this point in the history
* Hotfix/notifications list (#438)

* Hotfix/maintainance (#430)

* Feat/show running command (#427)

* fix: init flow, doctor epics, wip: running commands

* chore: lint

* fix: snackbar

* wip: setup npm cache, remove unused deps

* wip: cache verify flow

* chore: clean up

* Hotfix/search-flow (#431)

* wip

* chore: clean up

* chore: lint

* wip

* wip

* wip

* wip: notifications

* wip:notification epics

* fix: notification epics

* chore: lint

* chore: remove console.log

* Feat/npm cache (#443)

* wip: npm chache verify data flow

* chore: clean up
  • Loading branch information
rvpanoz authored Sep 15, 2019
1 parent dd2f8a9 commit 4f4e96d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 10 deletions.
8 changes: 6 additions & 2 deletions app/models/npm/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ const setEnv = ActionCreator('SET_ENV');
const setRunningCommand = ActionCreator('SET_RUNNING_COMMAND');
const npmCommand = ActionCreator('NPM_COMMAND');

// reporting
// npm utils
const parseNpmAuditData = ActionCreator('PARSE_NPM_AUDIT_DATA');
const parseNpmDoctorData = ActionCreator('PARSE_NPM_DOCTOR_DATA');
const parseNpmAuditFixData = ActionCreator('PARSE_NPM_AUDIT_FIX_DATA');
const parseNpmCacheData = ActionCreator('PARSE_NPM_CACHE_DATA');
const updateNpmAuditData = ActionCreator('UPDATE_NPM_AUDIT_DATA');
const updateNpmAuditFixData = ActionCreator('UPDATE_NPM_AUDIT_FIX_DATA');
const updateNpmDoctorData = ActionCreator('UPDATE_NPM_DOCTOR_DATA');
const updateNpmCacheData = ActionCreator('UPDATE_NPM_CACHE_DATA');
const clearAuditData = ActionCreator('CLEAR_AUDIT_DATA');
const clearDoctorData = ActionCreator('CLEAR_DOCTOR_DATA');

Expand Down Expand Up @@ -72,7 +74,9 @@ export {
parseNpmDoctorData,
parseNpmAuditData,
parseNpmAuditFixData,
parseNpmCacheData,
updateNpmAuditFixData,
updateNpmDoctorData,
updateNpmAuditData
updateNpmAuditData,
updateNpmCacheData
};
21 changes: 17 additions & 4 deletions app/models/npm/epics/cacheEpics.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import { pipe } from 'rxjs';
import { tap, switchMap, mergeMap } from 'rxjs/operators';
import { tap, map, switchMap, mergeMap, ignoreElements } from 'rxjs/operators';
import { ofType } from 'redux-observable';
import { ipcRenderer } from 'electron';
import { toggleLoader } from 'models/ui/actions';
import { runCache, npmCacheListener } from 'models/npm/actions';
import { runCache, npmCacheListener, parseNpmCacheData } from 'models/npm/actions';
import { iMessage } from 'commons/utils'
import { onNpmCache$ } from '../listeners';
import { updateNpmCacheData } from '../actions';

const updateLoader = payload => ({
type: toggleLoader.type,
payload
});

/**
* Parse npm cache verify data
*/

const npmCacheParseEpic = pipe(
ofType(parseNpmCacheData.type),
map(({ payload: data }) => updateNpmCacheData({
data
})),
ignoreElements()
)

/**
* Send ipc event to main process to handle npm-cache
*/
Expand All @@ -33,7 +46,7 @@ const npmRunCacheEpic = (action$, state$) =>
updateLoader({
loading: true,
message: iMessage('info', 'cacheRunning', {
'%action%': 'verify' // TODO: add more actions
'%action%': 'verify'
})
})]),
);
Expand All @@ -44,4 +57,4 @@ const npmRunCacheListenerEpic = pipe(
switchMap(() => onNpmCache$)
);

export { npmRunCacheEpic, npmRunCacheListenerEpic };
export { npmRunCacheEpic, npmRunCacheListenerEpic, npmCacheParseEpic };
4 changes: 3 additions & 1 deletion app/models/npm/epics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
import {
npmRunCacheEpic,
npmRunCacheListenerEpic,
npmCacheParseEpic
} from './cacheEpics';

export default combineEpics(
Expand All @@ -49,5 +50,6 @@ export default combineEpics(
npmRunDedupeEpic,
npmRunDedupeListenerEpic,
npmRunCacheEpic,
npmRunCacheListenerEpic
npmRunCacheListenerEpic,
npmCacheParseEpic
);
9 changes: 8 additions & 1 deletion app/models/npm/listeners/npmCache.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ipcRenderer } from 'electron';
import { Observable } from 'rxjs';
import { setRunningCommand } from 'models/npm/actions';
import { setRunningCommand, parseNpmCacheData } from 'models/npm/actions';
import { setSnackbar, toggleLoader } from 'models/ui/actions';

const updateCommand = ({
Expand All @@ -20,6 +20,13 @@ const onNpmCache$ = new Observable(observer => {
ipcRenderer.removeAllListeners(['npm-cache-completed']);

ipcRenderer.on('npm-cache-completed', (event, errors, data, action) => {
// TODO: npm cache errors
if (errors) {
console.error(errors)
}

observer.next(parseNpmCacheData(data));

observer.next(
updateCommand({
operationStatus: 'idle',
Expand Down
6 changes: 5 additions & 1 deletion app/reducers/initialState.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ const initialState = {
fix: false
},
doctor: {
data: null,
result: null,
error: false
},
cache: {
result: null,
error: false
}
},
Expand Down
10 changes: 9 additions & 1 deletion app/reducers/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
clearDoctorData,
updateNpmAuditData,
updateNpmAuditFixData,
updateNpmDoctorData
updateNpmDoctorData,
updateNpmCacheData
} from 'models/npm/actions';

import initialState from './initialState';
Expand All @@ -27,6 +28,13 @@ const createReducer = (npmState, handlers) => (state = npmState, action) =>
propOr(identity, prop('type', action), handlers)(state, action);

const handlers = {
[updateNpmCacheData.type]: (state, { payload: { data } }) =>
merge(state, {
cache: {
...state.cache,
result: data
}
}),
[updateNpmAuditData.type]: (state, { payload: { data } }) =>
merge(state, {
audit: {
Expand Down

0 comments on commit 4f4e96d

Please sign in to comment.