{"id":17704979,"url":"https://github.com/dwqs/redux-actions-promise","last_synced_at":"2025-10-22T20:40:33.245Z","repository":{"id":57350153,"uuid":"98091651","full_name":"dwqs/redux-actions-promise","owner":"dwqs","description":":rabbit: :cat: :bear: FSA-compliant promise middleware for Redux, supports referencing dispatcher/state in action.","archived":true,"fork":false,"pushed_at":"2018-09-23T08:29:56.000Z","size":51,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-25T01:04:34.731Z","etag":null,"topics":["fsa","fsa-actions","middleware","promise","redux","redux-middleware"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dwqs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-23T10:53:11.000Z","updated_at":"2025-01-14T09:41:49.000Z","dependencies_parsed_at":"2022-08-31T04:21:54.953Z","dependency_job_id":null,"html_url":"https://github.com/dwqs/redux-actions-promise","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwqs%2Fredux-actions-promise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwqs%2Fredux-actions-promise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwqs%2Fredux-actions-promise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwqs%2Fredux-actions-promise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dwqs","download_url":"https://codeload.github.com/dwqs/redux-actions-promise/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243369886,"owners_count":20280095,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fsa","fsa-actions","middleware","promise","redux","redux-middleware"],"created_at":"2024-10-24T22:05:43.651Z","updated_at":"2025-10-22T20:40:32.905Z","avatar_url":"https://github.com/dwqs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![build pass](https://api.travis-ci.org/dwqs/redux-actions-promise.svg?branch=master)](https://travis-ci.org/dwqs/redux-actions-promise) ![npm-version](https://img.shields.io/npm/v/redux-actions-promise.svg) ![license](https://img.shields.io/npm/l/redux-actions-promise.svg) ![bower-license](https://img.shields.io/bower/l/redux-actions-promise.svg)\n\n# redux-actions-promise\n\nFSA-compliant promise middleware for Redux, supports referencing dispatcher/state in action.\n\n## Installation\nInstall the pkg with npm:\n\n```\nnpm install redux-actions-promise --save\n```\n\nor yarn\n\n```\nyarn add redux-actions-promise\n```\n\nor bower\n\n```\nbower install redux-actions-promise\n```\n\n## Usage\n\n```\n// store.js\n// create store\nimport ReduxActionsPromise from 'redux-actions-promise';\nimport { createStore, applyMiddleware } from 'redux';\n\n// Note: this API requires redux@\u003e=3.1.0\nexport default createStore(rootReducer, applyMiddleware(ReduxActionsPromise));\n\n// actions.js\nimport {createAction} from 'redux-actions';\n\n// async action\nexport let addToDo = createAction(CONSTANT.ADD_TODO, (val) =\u003e async (dispatch, getState) =\u003e {\n    console.log('prev state', getState())\n    let v = await Promise.resolve('todo: ' + val);\n    return v;\n});\n\n// sync action\nexport let deleteToDo = createAction(CONSTANT.DELETE_TODO);\n```\n\n## FAQ\n1. why not use [redux-thunk](https://github.com/gaearon/redux-thunk) ?\n\n* I would like to use `createAction` for [FSA](https://github.com/acdlite/flux-standard-action).\n* I don't want to handle promise error in action by myself.\n\nIn `redux-thunk`:\n\n```\naddToDo = (val) =\u003e async (dispatch, getState) =\u003e {\n    let v = await Promise.reject('error');\n    // can't output in console\n    console.log('addToDo');\n    dispatch({\n        type: \"ADD_TODO\",\n        payload: {\n            val: v\n        }\n    })\n};\n```\n\nIf promise is rejected, the programme will be abort. So if you don't want this happen, you should handle it by yourself:\n\n```\naddToDo = (val) =\u003e async (dispatch, getState) =\u003e {\n    try{\n        let v = await Promise.reject('error');\n        // can't output in console\n        console.log('addToDo');\n        dispatch({\n            type: \"ADD_TODO\",\n            payload: {\n                val: v\n            }\n        })\n    } catch(e) {\n        dispatch({\n            type: \"ADD_TODO_ERROR\",\n            payload: e,\n            error: true\n        })\n    }\n};\n```\n\nUse [async-await-error-handling](https://github.com/dwqs/async-await-error-handling) maybe simple the code:\n\n```\nimport awaitTo from 'async-await-error-handling';\n\n//...\n\naddToDo = (val) =\u003e async (dispatch, getState) =\u003e {\n    const [err, data] = await awaitTo(Promise.reject('error'));\n    if(err){\n        dispatch({\n            type: \"ADD_TODO_ERROR\",\n            payload: e,\n            error: true\n        });\n        return;\n    }\n    dispatch({\n        type: \"ADD_TODO\",\n        payload: {\n            val: data\n        }\n    });\n};\n```\n\n2. why not use [redux-promise](https://github.com/acdlite/redux-promise) ?\n\nBecause it doesn't support referencing dispatcher or state in action. See [#20](https://github.com/acdlite/redux-promise/issues/20).\n\n## LICENSE\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwqs%2Fredux-actions-promise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdwqs%2Fredux-actions-promise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwqs%2Fredux-actions-promise/lists"}