{"id":25376840,"url":"https://github.com/terrierscript/redux-candy","last_synced_at":"2025-12-30T23:05:29.503Z","repository":{"id":57350406,"uuid":"77749824","full_name":"terrierscript/redux-candy","owner":"terrierscript","description":"redux + updeep = fantasy reducer","archived":false,"fork":false,"pushed_at":"2017-05-25T11:27:13.000Z","size":2572,"stargazers_count":3,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-15T04:39:38.386Z","etag":null,"topics":["react","redux"],"latest_commit_sha":null,"homepage":"","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/terrierscript.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-31T17:27:09.000Z","updated_at":"2017-07-13T13:06:47.000Z","dependencies_parsed_at":"2022-09-16T21:12:56.698Z","dependency_job_id":null,"html_url":"https://github.com/terrierscript/redux-candy","commit_stats":null,"previous_names":["inuscript/redux-candy"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terrierscript%2Fredux-candy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terrierscript%2Fredux-candy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terrierscript%2Fredux-candy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terrierscript%2Fredux-candy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/terrierscript","download_url":"https://codeload.github.com/terrierscript/redux-candy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248020592,"owners_count":21034459,"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","redux"],"created_at":"2025-02-15T04:39:51.455Z","updated_at":"2025-12-30T23:05:29.497Z","avatar_url":"https://github.com/terrierscript.png","language":"JavaScript","readme":"# 🍭 redux-candy \n\n*IMPORTANT:* This project maybe useful for development or toy but maybe not for produciton.\n\nGenerate redux [updeep](https://github.com/substantial/updeep) based reducer and actions.\n\n[![npm](https://img.shields.io/npm/v/redux-candy.svg?style=flat-square)](https://www.npmjs.com/package/redux-candy)\n[![Travis](https://img.shields.io/travis/inuscript/redux-candy.svg?style=flat-square)](https://travis-ci.org/inuscript/redux-candy)\n\n## Installation\n\n```\n$ npm install redux-candy\n```\n\n```\n$ yarn add redux-candy\n```\n\n## Example\n\n```js\nconst initialState = {\n  counter: 0\n}\nconst reducer = createReducer(initialState)\n\n// counter\nconst increment = createAction('INCREMENT', 'counter', (i) =\u003e i + 1 )\nconst decrement = createAction('DECREMENT', 'counter', (i) =\u003e i - 1 )\n\nconst Counter = ({dispatch, counter}) =\u003e {\n  return (\n    \u003cdiv\u003e\n      \u003cdiv\u003e{counter}\u003c/div\u003e\n      \u003cbutton onClick={() =\u003e dispatch(increment())}\u003eincrement\u003c/button\u003e\n      \u003cbutton onClick={() =\u003e dispatch(decrement())}\u003edecrement\u003c/button\u003e\n    \u003c/div\u003e\n  )\n}\n\nconst CounterContainer = connect(state =\u003e state)(Counter)\nconst store = createStore(reducer)\nconst App = () =\u003e (\n  \u003cProvider store={store}\u003e\n    \u003cCounterContainer /\u003e\n  \u003c/Provider\u003e\n)\n```\n\n### Live example\n* [Counter example](https://esnextb.in/?gist=e7e100d8af0dcb58bc6966335c36c084)\n* [Todo example](https://esnextb.in/?gist=9c6cd9623154aade7506d00e559b9680)\n\n[example source](https://github.com/inuscript/redux-candy/tree/master/example)\n\n# Usage\n\nredux-candy provide very stupid reducer that apply passed action.\n\n```js\nconst initialState = {\n  counter: 0\n}\nconst reducer = createReducer(initialState)\n```\n\nAnd you must pass action that has update function\n\n```js\n// counter\nconst increment = createAction('INCREMENT', 'counter', (i) =\u003e i + 1 )\nconst decrement = createAction('DECREMENT', 'counter', (i) =\u003e i - 1 )\n\n```\n\nYou can pass plain action like this.\n\n```js\nconst increment = () =\u003e {\n  type: 'INCREMENT',\n  payload: {\n    // [key]: updateFunction\n    counter: () =\u003e ( (i) =\u003e i + 1 )\n  }\n}\n```\n\nIf you want replace value\n\n```js\nconst replaceValueAction = createAction('INCREMENT', 'someValue')\n// or\nconst replaceValueAction = (value) =\u003e {\n  type: 'INCREMENT',\n  payload: {\n    // [key]: updateFunction\n    someValue: value\n  }\n}\n```\n\nYou can mutate oldValue\n\n```js\nconst listItemAppendAction = createAction('INCREMENT', 'someList', (oldList, value) =\u003e [...oldList, value]))\n// or\nconst listItemAppendAction = (value) =\u003e {\n  type: 'INCREMENT',\n  payload: {\n    // [key]: updateFunction\n    someList: (oldList) =\u003e [...oldList, value]\n  }\n}\n\n```\n\nYou can pass nested property.\n\n```js\nconst actionCreator = createAction('SOME_TYPE', ['a', 'b', 'c'])\nconst action = actionCreator('value')\n// or\nconst action = {\n  type: 'SOME_TYPE',\n  payload: {\n    a: {\n      b: {\n        c: 'value'\n      }\n    }\n  }\n})\n```\n\nYou can pass key-value action.\n\n```js\nconst actionCreator = createAction('SOME_TYPE', (userName, value) =\u003e {\n  return {\n    user: {\n      [userName]: value\n    }\n  }\n})\nconst action = actionCreator('bob', 100)\n```\n\n\n# API\n## Reducer\n\n### `createReducer(initialState: Object, [actionFilter: Function])`\n\nGenerate updeep based rootReducer.\nThis reducer accept all action and return `updeep(action.payload, state)`.\n\nThis reducer ignore below action too.\n\n* Not [flux standard action](https://github.com/acdlite/flux-standard-action).\n* Non object type payload action.\n  * Ignore action example: `{ type:\"TYPE\", payload: \"someValue\" }`\n\nIf you want controll update condition, pass `actionFilter`\n\n```js\nconst updateCondition = ( action ) =\u003e {\n  // update when pass SOME_ACTION\n  return action.type === \"SOME_ACTION\"\n}\n```\n\n## Action\n\nHelper for create action for redux-candy reducer.\nThis actionCreator return [FSA compatible](https://github.com/acdlite/flux-standard-action) action.\n\n### `createAction(actionType: String, targetProperty: String, [updateFunction: Function], [metaCreator: Function])`\n\nGenerate update targetProperty value action.\n\n```js\nconst actionCreator = createAction('ACTION', 'bob', (state, input) =\u003e state + input)\n\n// const initialState = { bob: 1 }\nstore.dispatch(actionCreator(10)))\n// state:\n// {\n//   bob: 11 // 1 + 10\n// }\n```\n\n`updateFunction` get arguments `(baseValue, ...inputs)`.\n\nAll action arguments pass to `updateFunction`. You can use that.\n\n```js\nconst actionCreator = createAction('ACTION', 'bob', (state, input1, input2) =\u003e state + input1 + input2)\n\nactionCreator(10, 20)\n```\n\n\n### `createAction(actionType: String, targetProperties: Array, [updateFunction: Function], [metaCreator: Function])`\n\nGenerate update targetProperty value action.\n\n```js\n// const initialState = { users: { bob: 1 } }\nconst complexActionCreator = createAction('ACTION', ['users', 'bob'], (state, val) =\u003e state + val)\nstore.dispatch(complexActionCreator(10)))\n// state:\n// {\n//   users: {\n//     bob: 11\n//   }\n// }\n```\n\n### `createAction(actionType: String, updateFunction: Function, [metaCreator: Function])`\n\nProxy [redux-action](https://github.com/acdlite/redux-actions#createactiontype-payloadcreator--identity-metacreator)\n\nYou can fully control payload.\n\n```js\n// const initialState = { bob: 1 }\nconst complexActionCreator = createAction('SOME_COMPLEX', (value, key) =\u003e {\n  return {\n    [key]: (i = 0) =\u003e (i + value)\n  }\n})\nstore.dispatch(complexActionCreator(10, 'bob')))\n// state:\n// {\n//   bob: 11\n// }\n\nstore.dispatch(complexActionCreator(10, 'bob')))\n// state:\n// {\n//   bob: 1,\n//   sam: 10\n// }\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterrierscript%2Fredux-candy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fterrierscript%2Fredux-candy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterrierscript%2Fredux-candy/lists"}