// Reducer and Epics of files
import { reducerWithInitialState } from 'typescript-fsa-reducers';
import { combineEpics } from 'redux-observable';
import actionCreatorFactory from 'typescript-fsa';
import { differenceBy } from 'lodash';
export var initialState = {
  files: []
};
var actionCreator = actionCreatorFactory('ide/file');
export var actions = {
  putFile: actionCreator('PUT_FILE'),
  putFiles: actionCreator('PUTS_FILES'),
  deleteFiles: actionCreator('DELETE_FILES')
};
export var epics = combineEpics();
export default reducerWithInitialState(initialState).case(actions.putFile, function (state, payload) {
  return {
    files: state.files.filter(function (file) {
      return file.name !== payload.name;
    }).concat(payload)
  };
}).case(actions.putFiles, function (state, payload) {
  return {
    files: differenceBy(state.files, payload, 'name').concat(payload)
  };
}).case(actions.deleteFiles, function (state, payload) {
  return {
    files: differenceBy(state.files, payload, 'id')
  };
});