Add a source to the state.
@param {Object} state Current state.
@param {Object} action Action to handle.

@returns {Object} The new state.
function addSource(state, action) {
  const new_source = {};

  new_source[action.sourceName] = Object.assign({}, action.sourceDef);
  if (action.sourceDef.type === 'geojson') {
    if (action.sourceDef.data === undefined || action.sourceDef.data === null) {
      new_source[action.sourceName].data = {};
    } else if (typeof action.sourceDef.data === 'object') {
      new_source[action.sourceName].data = Object.assign({}, action.sourceDef.data);
    } else {
      new_source[action.sourceName].data = action.sourceDef.data;
    }
  }

  const new_metadata = {};
  new_metadata[dataVersionKey(action.sourceName)] = 0;

  const new_sources = Object.assign({}, state.sources, new_source);
  return Object.assign({}, state, {
    metadata: Object.assign({}, state.metadata, new_metadata),
    sources: new_sources,
  }, incrementVersion(state.metadata, SOURCE_VERSION_KEY));

}