{"id":24089842,"url":"https://github.com/icemimosa/redux-creator","last_synced_at":"2025-05-06T01:54:56.986Z","repository":{"id":32554248,"uuid":"135901069","full_name":"IceMimosa/redux-creator","owner":"IceMimosa","description":"Redux Action and Reducer creator.","archived":false,"fork":false,"pushed_at":"2023-01-04T00:00:50.000Z","size":590,"stargazers_count":4,"open_issues_count":12,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-06T01:54:51.439Z","etag":null,"topics":["creator","redux","redux-create","redux-creator","redux-middleware"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/IceMimosa.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":"2018-06-03T12:12:40.000Z","updated_at":"2020-05-21T14:56:04.000Z","dependencies_parsed_at":"2023-01-14T21:45:15.790Z","dependency_job_id":null,"html_url":"https://github.com/IceMimosa/redux-creator","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/IceMimosa%2Fredux-creator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IceMimosa%2Fredux-creator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IceMimosa%2Fredux-creator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IceMimosa%2Fredux-creator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IceMimosa","download_url":"https://codeload.github.com/IceMimosa/redux-creator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252606926,"owners_count":21775413,"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":["creator","redux","redux-create","redux-creator","redux-middleware"],"created_at":"2025-01-10T05:00:31.286Z","updated_at":"2025-05-06T01:54:56.970Z","avatar_url":"https://github.com/IceMimosa.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Redux Action and Reducer creator.\n\n[![npm version](https://img.shields.io/badge/npm-v0.0.6-blue.svg)](https://www.npmjs.com/package/redux-all-creator)\n\n## 1. Install\n\n```sh\nnpm install --save redux-all-creator\n```\n\n* test\n\n```sh\n$ yarn\n$ yarn test\n```\n\n## 2. Usage\n\n```js\nimport * as ReduxCreator from 'redux-all-creator';\n```\n\n### 2.1 Create Action and Reducer\n\n```js\n// hello.js\nexport default ReduxCreator.create({\n  namespace: 'hello',\n  actions: {\n    hello: ReduxCreator.createAction((data) =\u003e { \n      return `Hello ${data}`;\n    })\n  },\n  reducers: {\n    hello: ReduxCreator.createReducer((on, actions) =\u003e {\n      on(actions.hello).completed((state, action) =\u003e {\n        return action.payload;\n      })\n    }, '')\n  }\n});\n\n// or pure hello.js\nexport default ReduxCreator.create({\n  namespace: 'hello',\n  actions: {\n    hello: (data) =\u003e { \n      return `Hello ${data}`;\n    }\n  },\n  reducers: {\n    hello: (on, actions) =\u003e {\n      on(actions.hello).completed((state, action) =\u003e {\n        return action.payload;\n      })\n    } // initialState is {}\n  }\n});\n```\n\n### 2.2 Connect all creators\n\nConnect all creators and get reducers object.\n\n```js\nimport * as ReduxCreator from 'redux-all-creator';\nimport HelloCreator from './examples/hello';\n\n// create connector\nconst connector = ReduxCreator.connect(HelloCreator, ...);\n\n// create redux store\nconst middlewares = [];\nconst store = Redux.createStore(\n  Redux.combineReducers(connector.getReducers()),\n  Redux.applyMiddleware(...middlewares)\n);\n\n// jest test\nit('hello world', () =\u003e {\n  const data = 'Redux Creator';\n  store.dispatch(HelloCreator.hello(data))\n  // hello is reduce key\n  expect(store.getState().hello).toBe(`Hello ${data}`);\n})\n```\n\n* [More Examples](https://github.com/IceMimosa/redux-creator-test) OR `__tests__ directory`.\n\n\n## 3. FetchStatus Middleware\n\nYou can get status(**true** or **false**) before and after Fetch(Promise) action. You should also use [redux-promise](https://github.com/redux-utilities/redux-promise).\n\n* import middleware\n\n```js\nimport promiseMiddleware from 'redux-promise';\nimport * as ReduxCreator from 'redux-all-creator';\n\nconst middlewares = [ ReduxCreator.fetchStatusMiddleware, promiseMiddleware ];\n```\n\n* create action and reducer\n\n```js\n// promise.js\n\n// delay方法\nconst delay = (time) =\u003e (result) =\u003e new Promise(resolve =\u003e setTimeout(() =\u003e resolve(result), time));\n\n// !!! important: add fetch property to true\nexport default ReduxCreator.create({\n  namespace: 'TestPromise',\n  actions: {\n    promiseStatus: ReduxCreator.createAction((id) =\u003e { \n      return Promise.resolve({ body: `Promise Status ${id}` }).then(delay(2000)).then(res =\u003e res.body)\n    }, { fetch: true })\n  },\n  reducers: {\n    promise: ReduxCreator.createReducer((on, actions) =\u003e {\n      on(actions.promiseStatus).completed((state, action) =\u003e {\n        return action.payload;\n      });\n    }, {})\n  }\n});\n```\n\n* get fetch status\n\n```js\nimport PromiseCreator from './example/promise';\n\nit('test promise status', (done) =\u003e {\n  const id = 1;\n  store.dispatch(PromiseCreator.promiseStatus(id))\n    .then(it =\u003e { \n      const state = store.getState();\n      expect(state.promise).toBe(`Promise Status ${id}`);\n      // fetch end\n      const fetchStatus = ReduxCreator.getFetchStatus(state, PromiseCreator.promiseStatus);\n      expect(fetchStatus).toBe(false);\n      done();\n    });\n  // fetch start\n  const state = store.getState();\n  const fetchStatus = ReduxCreator.getFetchStatus(state, PromiseCreator.promiseStatus)\n  expect(fetchStatus).toBe(true);\n})\n```\n\n## Some examples\n\n* [IceMimosa/react-antd-example](https://github.com/IceMimosa/react-antd-example)\n\n## Todo\n\n* [ ] Promise data cache\n* [ ] Connect with React\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficemimosa%2Fredux-creator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficemimosa%2Fredux-creator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficemimosa%2Fredux-creator/lists"}