{"id":22727293,"url":"https://github.com/noviel/redaim","last_synced_at":"2025-07-31T19:32:50.749Z","repository":{"id":98890804,"uuid":"95538507","full_name":"Noviel/redaim","owner":"Noviel","description":"Redaim - reusable actions and reducers for redux. Aim domain's target.","archived":false,"fork":false,"pushed_at":"2017-08-16T14:05:28.000Z","size":53,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-05T02:17:18.783Z","etag":null,"topics":[],"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/Noviel.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-27T08:58:32.000Z","updated_at":"2017-06-27T09:11:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"6b757926-f027-497c-8664-2787a3fd586d","html_url":"https://github.com/Noviel/redaim","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noviel%2Fredaim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noviel%2Fredaim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noviel%2Fredaim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noviel%2Fredaim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Noviel","download_url":"https://codeload.github.com/Noviel/redaim/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246260575,"owners_count":20748887,"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":[],"created_at":"2024-12-10T17:11:40.600Z","updated_at":"2025-03-30T00:23:57.689Z","avatar_url":"https://github.com/Noviel.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Redaim\n\nRedaim - reusable actions and reducers for redux. Aim domain's target.\n\n## Concepts\n\nAdd additional dimension for actions and reducers to specify where exactly on the state tree action should be applied.\n\n## Install\n```sh\nyarn add redaim\n``` \nor \n```sh\nnpm install redaim --save\n```\n\n## Usage\n\nRedaim stands on several conceptual elements:\n- Domain\n- Target\n- Exection (exec-action)\n\n### Targets\nTargets are reducers grouped in one namespace. Target can be created with `handlers` object by `createTarget`:\n\n```javascript\n// counter-target.js\nimport { createTarget } from 'redaim';\n\nconst counterHandlers = {\n  INCREMENT: (state, action) =\u003e state + 1, \n  DECREMENT: (state, action) =\u003e state - 1,\n  SET: (state, action) =\u003e action.payload\n};\n\nexport default createTarget(counterHandlers);\n```\n\nCreated target should be passed to namespace.\n\n### Namespaces\nNamespaces are reducers with targets. Namespace will take action and will pass it to corresponding target.\n\n```javascript\n// counters-namespace.js\nimport createNamespace from 'redaim';\nimport counterTarget from './counter-target';\n\nconst countersNamespace = createNamespace({\n  counter1: counterTarget(0),\n  counter2: counterTarget(100),\n  counter3: counterTarget(-100)\n}, 'COUNTERS');\n\nexport default countersNamespace;\n```\n\nNote that `counterTarget` is a function that takes `initialState` as an argument.\n\nredaim namespace reducer can be used along side with any other reducers:\n\n```javascript\n// root-reducer.js\nimport { combineReducers } from 'redux';\nimport counterNamespace from './counters-namespace.js';\n\nconst rootReducer = combine({\n  plain: myPlainReducer,\n  counters: counterNamespace\n});\n\nexport default rootReducer;\n```\n\n### Exec-actions\n\nDifferences from plain redux actions:\n1. should have `exec` and `target` fields\n2. `type` is used as a `trigger` to determine on which namespace it should be used\n\n```javascript\n// Simple redaim-action\nconst action = {\n  type: 'COUNTERS',\n  meta: {\n    target: 'counter1',\n    exec: 'INCREMENT'\n  }\n};\n```\nSame action can be created with `createAction`:\n\n```javascript\nimport { createAction } from 'redaim';\n\nconst actionDescriptor = { exec: 'INCREMENT' };\n\n// return [Function]\nconst withTrigger = createAction('COUNTERS');\n\n// return [Function]\nconst withTriggerAndTarget = withTrigger('counter1');\n\n// return final action object\nconst action = withTriggerAndTarget(actionDescriptor);\n```\n`createAction` is a higher-order function, so it can be bound to specific namespace and/or target.\n\nTo bind multiple actions can be used `createActions`:\n\n```javascript\n// actions.js\nimport { createActions } from 'redaim';\n\nconst actionsObject = {\n  increment: { exec: 'INCREMENT' },\n  decrement: { exec: 'DECREMENT' }\n  // actions in action object could be functions.\n  set: value =\u003e ({ exec: 'SET', payload: value }),\n};\n\n// we can hard bind to `COUNTERS` namespace if we are sure \n// that it is the only place where actions will be used\nconst countersActions = createActions('COUNTERS');\n\nexport default function getActions(target) {\n  return countersActions(target)(actionsObject);\n}\n```\n\n```javascript\n// index.js\nimport getActions from './actions.js';\nimport getStore from './store.js';\n\nconst counterOneActions = getActions('counter1');\nconst counterTwoActions = getActions('counter2');\nconst store = getStore();\n\nstore.dispatch(counterOneActions.increment());\n/* action:\n{ \n  type: 'COUNTERS',\n  meta: {\n    exec: 'INCREMENT',\n    target: 'counter1'\n  }\n}\n*/\n\nstore.dispatch(counterTwoActions.set(10));\n/* action:\n{ \n  type: 'COUNTERS',\n  meta: {\n    exec: 'SET',\n    target: 'counter2'\n  },\n  payload: 10\n}\n*/\n```\n\n## Examples\n\n### [counter](https://github.com/Noviel/redaim/tree/master/src/example/counter)\n\n## API\n\n### Targets\n\n#### createTarget\n- signature :: handlers -\u003e initialState -\u003e { initialState, reducer }\n\n### Namespaces\n\n#### createNamespace\n- signature :: (targets, trigger) -\u003e reducer\n\n#### createNamespaceObject\n- signature :: (targets, namespace) -\u003e { namespace: reducer }\n\n### Exections\n\n#### createAction\n- signature :: string -\u003e string -\u003e { exec, payload, meta} -\u003e { type, meta, payload }\n\n#### wrapActions\n- signature :: F (...args -\u003e action) -\u003e { ...action } -\u003e { ...F(action) }\n\n#### bindActions\n- signature :: (F actionCreatorWithTrigger -\u003e target -\u003e { ...action }) -\u003e { ...F(action) }\n\n#### createActions\n- signature :: string -\u003e string -\u003e { ...action } -\u003e { ...action }\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoviel%2Fredaim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoviel%2Fredaim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoviel%2Fredaim/lists"}