Skip to content

Instantly share code, notes, and snippets.

@zackshapiro
Created June 14, 2019 23:17
Show Gist options
  • Save zackshapiro/1866206d9bb9368326cbbb4f4b5c64c2 to your computer and use it in GitHub Desktop.
Save zackshapiro/1866206d9bb9368326cbbb4f4b5c64c2 to your computer and use it in GitHub Desktop.
const reducer = (state, action) => {
switch (action.type) {
case 'load':
return { ...state, files: action.files, status: LOADED }
case 'submit':
return { ...state, uploading: true, pending: state.files, status: INIT }
case 'next':
return {
...state,
next: action.next,
status: PENDING,
}
case 'file-uploaded':
return {
...state,
next: null,
pending: action.pending,
uploaded: {
...state.uploaded,
[action.prev.id]: action.prev.file,
},
}
case 'set-upload-error':
return { ...state, uploadError: action.error, status: UPLOAD_ERROR }
default:
return state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment