Skip to content

Instantly share code, notes, and snippets.

@kafaichoi
Last active May 30, 2017 06:16
Show Gist options
  • Save kafaichoi/0b4e375ad476e7cbd4ca63ffaef6c74b to your computer and use it in GitHub Desktop.
Save kafaichoi/0b4e375ad476e7cbd4ca63ffaef6c74b to your computer and use it in GitHub Desktop.
JS Tips
// Using proxy in redux action.
const types = {
  FETCH_FILE_REQUEST: 'fetch_file_request',
  FETCH_FILE_SUCCESS: 'fetch_file_success',
  FETCH_FILE_FAIL: 'fetch_file_fail'
}

const typeValidator = {
  get(obj, prop) {
    if (obj[prop]) {
      return prop;
    } else {
      throw new TypeError(`${prop} is not a valid action type`);
    }
  }
}

module.exports = new Proxy(types, typeValidator);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment