{"id":15412772,"url":"https://github.com/molefrog/redux-actuator","last_synced_at":"2025-08-11T16:07:54.266Z","repository":{"id":57350240,"uuid":"77916558","full_name":"molefrog/redux-actuator","owner":"molefrog","description":"☎️ Communicate between components through Redux store","archived":false,"fork":false,"pushed_at":"2017-12-06T00:59:43.000Z","size":3319,"stargazers_count":39,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T23:51:38.750Z","etag":null,"topics":["animations","reactjs","redux"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/molefrog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-03T12:47:54.000Z","updated_at":"2025-03-03T14:43:52.000Z","dependencies_parsed_at":"2022-08-28T19:40:16.944Z","dependency_job_id":null,"html_url":"https://github.com/molefrog/redux-actuator","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/molefrog%2Fredux-actuator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/molefrog%2Fredux-actuator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/molefrog%2Fredux-actuator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/molefrog%2Fredux-actuator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/molefrog","download_url":"https://codeload.github.com/molefrog/redux-actuator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249604083,"owners_count":21298420,"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":["animations","reactjs","redux"],"created_at":"2024-10-01T16:54:18.101Z","updated_at":"2025-04-19T04:15:05.757Z","avatar_url":"https://github.com/molefrog.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Redux Actuator\n[![Build Status](https://travis-ci.org/molefrog/redux-actuator.svg?branch=master)](https://travis-ci.org/molefrog/redux-actuator)\n\nTrigger events inside components by reacting on pure state changes. Actuator keeps you from writing\ncomponent lifecycle hooks boilerplate code by providing declarative API.\n\n## Motivation\nIn Redux apps subscribing to events inside components is typically considered as an anti-pattern.\nComponents should be as pure as possible, meaning that they shouldn't have an internal state and\nthey can only respond to props changes. This makes even more sense if we take into an account\nthat React is [\"pull\"-based](https://facebook.github.io/react/contributing/design-principles.html): you\ndon't have a control over rendering, you simply take the data and provide corresponding piece of DOM.\n\nBut there are cases when you want to comminicate with components in an imperative way. Imagine if\nyou have an `\u003cIframePreview\u003e` component and you need to manually reload it when the button\nis clicked. One possible way to achieve that is to introduce an integer prop `version`\nand increment it on click.\n\n![](assets/actuate-iframe.gif)\n\nThe `\u003cIframePreview\u003e` external interface remains pure while its internal implementation uses\n[`componentDidUpdate`](https://facebook.github.io/react/docs/react-component.html#componentdidmount)\ncallback in order to detect `version` changes and reload the iframe:\n\n```JavaScript\nclass IframePreview extends Component {\n  componentDidUpdate (prevProps) {\n    if (prevProps.version !== this.props.version) {\n      this.reloadIframe()\n    }\n  }\n}\n```\nWhen the app gets bigger the good idea is to move this counter to global state so you can control the\niframe from where the bussiness logic resides. In Redux you have to declare action constant, write a reducer\nand action creator which isn't a problem for one component but becomes repetitive once you have more events\nand listening components. **Redux Actuator** aims to hide this logic and provide declarative API for event\nhandling inside components.\n\n## Installation\nRedux Actuator is distributed as an NPM package:\n\n```\nnpm install --save redux-actuator\n# or yarn add redux-actuator\n```\n\nHere how Redux Actuator is injected into Redux store:\n```JavaScript\n  import createEngine from 'redux-actuator'\n\n  const engine = createEngine()\n\n  const reducer = combineReducers({\n    // It's important for the reducer to be mounted at `actuator`\n    // If you'd like to set up different mounting point see Configuration section.\n    actuator: engine.reducer,\n\n    // ... your other reducers\n  })\n```\nThat's it! Now we are ready to actuate!\n\n## Simpliest Actuator\nOne common use case for an actuator are state-free animations. Say, you want to animate\nthis talking head:\n\n![](assets/talking-guy.gif)\n\nIn order to do that simply put `\u003cActuator\u003e` component with channel provided.\n\n```JavaScript\n  import { Actuator } from 'redux-actuator'\n\n  class ThisGuy extends React.Component {\n    saySomething (phrase) {\n      // animation, DOM manipulation etc.\n    }\n\n    render () {\n      // Actuator can wrap other components for brevity,\n      // or can be used in a self-closing form \u003cActuator /\u003e\n      return (\n        \u003cActuator channel=\"talking-guy\" on={(phrase) =\u003e this.saySomething(phrase)}\u003e\n          \u003cdiv\u003e\n            ...\n          \u003c/div\u003e\n        \u003c/Actuator\u003e)\n    }\n  }\n```\n\nNow let's trigger actions from the bussiness-logic part of the app:\n\n```JavaScript\n  import { actuate } from 'redux-actuator'\n\n  // First argument is name of the event,\n  // the rest is interpreted as event arguments\n  store.dispatch(actuate('talking-guy', 'Hola!')\n  store.dispatch(actuate('talking-guy', 'Hello!')\n```\n\n**Subscribing to multiple channels.** You can also subscribe to a multiple channels at once using this form:\n\n```JavaScript\n  // Note: no need to pass a `channel` prop\n  // Format is { chanOne: handler, chanTwo: ... }\n  \u003cActuator on={{\n    instantNotification: () =\u003e ..., \n    focusToolbar: () =\u003e ...\n   }} /\u003e\n```\n\n## License\nCopyright 2017, Alexey Taktarov \u003cmolefrog@gmail.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmolefrog%2Fredux-actuator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmolefrog%2Fredux-actuator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmolefrog%2Fredux-actuator/lists"}