Remove features from a source.
The action should define a filter, any feature
matching the filter will be removed.
@param {Object} state Current state.
@param {Object} action Action to handle.

@returns {Object} The new state.
function removeFeatures(state, action) {
  // short hand the source source and the data
  const source = state.sources[action.sourceName];
  if (!source) {
    return state;
  }
  const data = source.data;

  // filter function, features which MATCH this function will be REMOVED.
  const match = createFilter(action.filter);

  if (data.type === 'Feature') {
    // if the feature should be removed, return an empty
    //  FeatureCollection
    if (match(undefined, data)) {
      return changeData(state, action.sourceName, {
        type: 'FeatureCollection',
        features: [],
      });
    }
  } else if (data.type === 'FeatureCollection') {
    const new_features = [];
    for (let i = 0, ii = data.features.length; i < ii; i++) {
      const feature = data.features[i];
      if (!match(undefined, feature)) {
        new_features.push(feature);
      }
    }

    const new_data = Object.assign({},
      data,
      {features: new_features},
    );

    return changeData(state, action.sourceName, new_data);
  }

  return state;
}