{"id":22317145,"url":"https://github.com/oplog/resource-redux","last_synced_at":"2025-06-19T07:35:31.031Z","repository":{"id":33753409,"uuid":"161202291","full_name":"oplog/resource-redux","owner":"oplog","description":"Generic http resource store for redux ","archived":false,"fork":false,"pushed_at":"2023-03-03T00:27:24.000Z","size":2202,"stargazers_count":10,"open_issues_count":12,"forks_count":2,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-04-28T20:44:55.162Z","etag":null,"topics":["react","react-redux","redux","redux-saga","typescript"],"latest_commit_sha":null,"homepage":"https://oplog.github.io/resource-redux","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/oplog.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-12-10T16:17:06.000Z","updated_at":"2022-04-18T12:46:26.000Z","dependencies_parsed_at":"2023-09-27T04:50:57.679Z","dependency_job_id":null,"html_url":"https://github.com/oplog/resource-redux","commit_stats":{"total_commits":31,"total_committers":7,"mean_commits":4.428571428571429,"dds":0.6774193548387097,"last_synced_commit":"f0619c710e891e861dbdd2171aabc946fd22c867"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oplog%2Fresource-redux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oplog%2Fresource-redux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oplog%2Fresource-redux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oplog%2Fresource-redux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oplog","download_url":"https://codeload.github.com/oplog/resource-redux/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228012281,"owners_count":17855984,"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":["react","react-redux","redux","redux-saga","typescript"],"created_at":"2024-12-03T23:08:52.223Z","updated_at":"2024-12-03T23:08:52.909Z","avatar_url":"https://github.com/oplog.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Resource Redux\nResource redux is a redux library for easily managing http resources lifecyle. It works with `redux-saga`, `react-redux` and `redux`. It has builtin reusable store actions (generators), reducer and selectors.\n\n## Installation\n- Installing from npm registry\n```sh\nnpm i --save resource-redux\n```\n- You can also manually clone \u0026 build if you have lerna use cases\n```sh\ngit clone git@github.com:oplog/resource-redux.git\n```\n\n## The Design\nIn resource-redux, each http resource is defined as the following model;\n```ts\nexport interface Resource\u003cT\u003e {\n    data?: T; // The data that is returned from the http call\n    error?: Error; // The error (non HTTP 200) body that is returned from the http call\n    isBusy: boolean; // Represents the request continuity\n    isSuccess: boolean; // Represents the request is successfully returned\n}\n```\n\nThese http resource states are kept in redux state tree as the following model;\n```ts\n{\n    \"createUser\": Resource\u003cany\u003e,\n    \"updateUser\": Resource\u003cany\u003e\n}\n```\n\nThe state is mutated by the resourceType (i.e \"createUser\"), builtin actions \u0026 reducer.\n\n## Getting Started\n\nIn your store type definition add resource store state;\n```ts\nimport { ResourceStoreState } from \"resource-redux\";\n\nexport interface StoreState {\n    // other type definitions of store\n    resources: ResourceStoreState;\n}\n```\n\n#### Add resource types for a model definition;\n```ts\nexport enum ResourceType {\n    CreateUser = \"createUser\" // Here, string enums are required\n    UpdateUser = \"updateUser\"\n}\n```\n\n#### Add initial states of your resources;\n\n```ts\nimport { initialResourceState } from \"resource-redux\";\n\n// This is the initial state of your redux state configuration\nexport const initialState = {\n    resources: {\n        [ResourceType.CreateUser]: { ...initialResourceState },\n        [ResourceType.UpdateUser]: { ...initialResourceState }\n    }\n}\n```\n\n#### Create a http api map and configure your redux saga middleware\n\nHttp api map is a dictionary which has the resource type as keys and http call functions as the value;\n```ts\n\nexport type RequestParams = Dictionary\u003cany\u003e;\n\nfunction createUser(params: RequestParams) {\n    const accessToken = getAccessToken();\n    // Here the following function performs an http call and returns the Promise object\n    // The following function is auto generated by swagger\n    return api.Users.apiCreateUser(\n        params.createUser, // These are the post body parameters that is passed by resource redux saga\n        addAuthToHeader(accessToken)\n    ).then(r =\u003e r);\n}\n\nconst resourceApiMap = {\n  [ResourceType.CreateUser]: createUser,\n}\n\n// middleware configuration\nexport const resources = resourceStore({\n  httpRequestMap: resourceApiMap,\n});\n\nsagaMiddleware.run(resources.resourceSaga); // This is required for saga to catch your requested actions\n```\n\n#### Mapping props to store \u0026 Dispatching actions in containers;\n```ts\nimport { resourceActions, resourceSelectors } from \"resource-redux\";\n\nfunction mapStateToProps({resources}: StoreState) {\n    return {\n        user: resourceSelectors.getData(resources, ResourceType.User)\n    };\n}\n\nfunction mapDispatchToProps(dispatch: Dispatch\u003cresourceActions.ResourceAction\u003e) {\n    return {\n        onUserSubmit: (userFormModel) =\u003e {\n            dispatch(\n                resourceActions.resourceRequested(ResourceType.CreateUser, {\n                    userFormModel // These parameters are mapped into post body parameters defined in http request api map's createUser() function\n                })\n            );\n        }\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foplog%2Fresource-redux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foplog%2Fresource-redux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foplog%2Fresource-redux/lists"}