'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.triggerModified = undefined;

var _immutable = require('immutable');

var _reduxObservable = require('redux-observable');

var _epics = require('./epics');

var _epics2 = _interopRequireDefault(_epics);

var _constants = require('./constants');

var constants = _interopRequireWildcard(_constants);

var _actions = require('./actions');

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const triggerModified = exports.triggerModified = store => next => action => {
  const ignore = new _immutable.List([constants.CHANGE_FILENAME, constants.NEW_KERNEL, constants.KILL_KERNEL, constants.INTERRUPT_KERNEL, constants.SET_NOTEBOOK, constants.UPDATE_CELL_EXECUTION_COUNT, constants.CHANGE_OUTPUT_VISIBILITY, constants.CHANGE_INPUT_VISIBILITY, constants.UPDATE_CELL_PAGERS, constants.SET_LANGUAGE_INFO, constants.SET_EXECUTION_STATE, constants.FOCUS_CELL, constants.FOCUS_NEXT_CELL, constants.FOCUS_PREVIOUS_CELL, constants.TOGGLE_STICKY_CELL, constants.STARTED_UPLOADING, constants.DONE_UPLOADING, constants.SET_NOTIFICATION_SYSTEM, constants.ASSOCIATE_CELL_TO_MSG, constants.SET_FORWARD_CHECKPOINT, constants.SET_BACKWARD_CHECKPOINT, constants.CLEAR_FUTURE, constants.SET_MODIFIED]);

  if (ignore.indexOf(action.type) === -1) {
    store.dispatch((0, _actions.setModified)(true));
  }
  if (action.type === constants.DONE_SAVING) {
    store.dispatch((0, _actions.setModified)(false));
  }

  return next(action);
};

const rootEpic = (0, _reduxObservable.combineEpics)(..._epics2.default);

const middlewares = [(0, _reduxObservable.createEpicMiddleware)(rootEpic), triggerModified];

exports.default = middlewares;