putDataFile = (
  directory,
  filename,
  data,
  new_path = '',
  source = 'editor'
) => (dispatch, getState) => {
  const ext = getExtensionFromPath(new_path || filename);

  if (source === 'gui') {
    const json = /json/i.test(ext);
    let metadata = getState().metadata.metadata;
    metadata = trimObject(metadata);
    data = json ? JSON.stringify(metadata, null, 2) : toYAML(metadata);
  }

  const payload = new_path
    ? { path: new_path, raw_content: data }
    : { raw_content: data };

  // handle errors
  const errors = validateDatafile(filename, data);
  if (errors.length) {
    return dispatch(validationError(errors));
  }
  dispatch(clearErrors());

  return put(
    datafileAPIUrl(directory, filename),
    JSON.stringify(payload),
    { type: PUT_DATAFILE_SUCCESS, name: 'file' },
    { type: PUT_DATAFILE_FAILURE, name: 'error' },
    dispatch
  );
}
Creates and updates a data file.
@param {String} directory : Dirname of data file
@param {String} filename  : The data file
@param {Object} data      : Content to be written to data file
@param {String} new_path  : File path relative to config['source']
@param {String} source    : Point of origin of file-content data.
                            Either the default `#brace-editor`, or `<DataGUI/>`