{"id":21999070,"url":"https://github.com/ptol/ts-reducer-creator","last_synced_at":"2025-04-30T21:47:20.394Z","repository":{"id":57381077,"uuid":"142662523","full_name":"ptol/ts-reducer-creator","owner":"ptol","description":"TypeScript strongly typed boilerplate-free reducer creator for Redux and ngrx","archived":false,"fork":false,"pushed_at":"2018-07-31T18:32:07.000Z","size":264,"stargazers_count":45,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-08T17:04:27.051Z","etag":null,"topics":["angular","ngrx","react","redux"],"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/ptol.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-07-28T08:57:47.000Z","updated_at":"2024-08-23T17:16:44.000Z","dependencies_parsed_at":"2022-08-28T21:21:54.774Z","dependency_job_id":null,"html_url":"https://github.com/ptol/ts-reducer-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/ptol%2Fts-reducer-creator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptol%2Fts-reducer-creator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptol%2Fts-reducer-creator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptol%2Fts-reducer-creator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ptol","download_url":"https://codeload.github.com/ptol/ts-reducer-creator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227225708,"owners_count":17750729,"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":["angular","ngrx","react","redux"],"created_at":"2024-11-29T22:27:34.501Z","updated_at":"2024-11-29T22:27:35.286Z","avatar_url":"https://github.com/ptol.png","language":"TypeScript","readme":"# Install\n`npm install ts-reducer-creator`\n\n# How to use\n\nFirst you need to define your actions and their payload types\n```typescript\ninterface CounterActions {\n    setValue: number; \\\\\"setValue\" is an action and number is a payload type \n    increment: void;    \n}\n\n```\nand State\n```typescript\nexport interface State {\n    value: number;\n}\n\nexport const initialState: State = {\n    value: 0\n}\n```\n\nThen you can call `createHelpers`\n```typescript\nimport {createHelpers} from 'ts-reducer-creator';\n\nexport const {reducer, actionCreators, ofTypeFilters, actionTypes} =\n  createHelpers\u003cState, CounterActions\u003e('Counter', initialState, {\n    increment: (state) =\u003e {\n        return {...state, value: state.value + 1}; // state has type State\n    },\n    setValue: (state, payload) =\u003e {\n        return {...state, value: payload};   // payload has type number\n    },\n});\n```\nto create\n\n* **reducer** - your reducer function\n* **actionCreators** - action creators `actionCreators.setValue(10)`\n* **ofTypeFilters** - action filters for `Obserable\u003cAction\u003e`. It can be used with `redux-observable` or `ngrx effects` `actions$.pipe(ofTypeFilters.increment)`\n* **actionTypes** - action types `actionTypes.increment`\n\n# Boilerplate vs ts-reducer-creator \n\n## Boilerplate\n```typescript\nexport enum CounterActionTypes {\n  INCREMENT = '[Counter] Increment',\n  SET_VALUE = '[Counter] SetValue'\n}\n\nexport class Increment implements Action {\n    readonly type = CounterActionTypes.INCREMENT;\n}\n\nexport class SetValue implements Action {\n    readonly type = CounterActionTypes.SET_VALUE;\n    constructor(public payload: number) {}\n}\n\nexport type CounterActionsUnion = Increment | SetValue;\n\nexport function reducer(state = initialState, action: CounterActionsUnion): State {\n  switch (action.type) {\n    case CounterActionTypes.INCREMENT: {\n      return {...state, value: state.value + 1};\n    }\n\n    case CounterActionTypes.SET_VALUE: {\n      return {value: action.payload};\n    }\n\n    default: {\n      return state;\n    }\n  }\n}\n\nconst actionCreators = {\n  increment: () =\u003e new Increment(),\n  setValue: (payload: number) =\u003e new SetValue(payload),\n}\n```\n## ts-reducer-creator\n```typescript\ninterface CounterActions {\n    increment: void;\n    setValue: number;\n}\n\nexport const {reducer, actionCreators} = createHelpers\u003cState, CounterActions\u003e('Counter', initialState, {\n    increment: (state) =\u003e {\n        return {...state, value: state.value + 1}; \n    },\n    setValue: (state, payload) =\u003e {\n        return {...state, value: payload};  \n    }\n});\n```\n# Examples\nhttps://github.com/ptol/ts-reducer-creator/tree/master/examples\n\n## Angular with ngrx\nhttps://github.com/ptol/ts-reducer-creator/blob/master/examples/angular/src/app/newStore.ts\n\n## React with redux and redux-observable\nhttps://github.com/ptol/ts-reducer-creator/blob/master/examples/react/src/newStore.ts\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fptol%2Fts-reducer-creator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fptol%2Fts-reducer-creator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fptol%2Fts-reducer-creator/lists"}