{"id":13804391,"url":"https://github.com/salsita/prism","last_synced_at":"2025-04-06T01:10:50.116Z","repository":{"id":57220975,"uuid":"50673771","full_name":"salsita/prism","owner":"salsita","description":"React / Redux action composition made simple http://salsita.github.io/prism/","archived":false,"fork":false,"pushed_at":"2017-05-30T09:53:42.000Z","size":2353,"stargazers_count":495,"open_issues_count":10,"forks_count":24,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-12-20T09:27:57.143Z","etag":null,"topics":["composition","elm-architecture","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/salsita.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":"2016-01-29T16:10:28.000Z","updated_at":"2024-09-23T11:30:50.000Z","dependencies_parsed_at":"2022-08-29T02:12:58.642Z","dependency_job_id":null,"html_url":"https://github.com/salsita/prism","commit_stats":null,"previous_names":["salsita/redux-elm"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salsita%2Fprism","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salsita%2Fprism/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salsita%2Fprism/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salsita%2Fprism/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/salsita","download_url":"https://codeload.github.com/salsita/prism/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247419861,"owners_count":20936012,"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":["composition","elm-architecture","react","redux"],"created_at":"2024-08-04T01:00:46.984Z","updated_at":"2025-04-06T01:10:50.098Z","avatar_url":"https://github.com/salsita.png","language":"TypeScript","funding_links":[],"categories":["Code Architecture","TypeScript"],"sub_categories":[],"readme":"# [prism](http://salsita.github.io/prism)\n\n\u003e React / Redux action composition made simple\n\nGiven function `f` and function `g` we can simply compose them: `f ∘ g = f(g())`.\n\nFunction composition in JavaScript is just a matter of calling function and passing the result as input to other function. This thesis can be applied to [React Components](https://facebook.github.io/react/docs/react-component.html) and [Redux Reducers](http://redux.js.org/docs/basics/Reducers.html) as well, because functional stateless Component is nothing but function of its props (state of the application) and Reducer is just another plain JavaScript function. Can we compose [actions](http://redux.js.org/docs/basics/Actions.html)?\n\nYes we can! Let's just call it action wrapping. Because it's the same principle like you would be wrapping a box inside a box, the last box in the hierarchy contains some object and that's the Action. We can just wrap action type to keep things simple and because action type is just a string, it's as easy as function composition.\n\n```javascript\nconst wrapWithFoo = actionType =\u003e `Foo.${actionType}`;\nconst wrapWithBar = actionType =\u003e `Bar.${actionType}`;\n\nconst composedActionType = wrapWithFoo(wrapWithBar('Baz'));\n\n// Composed action type would be 'Foo.Bar.Baz';\n```\n\n## What is it good for?\n\nImagine you've just implemented your awesome Calendar widget, but then comes a new requirement and you need to have two of those widgets on page so that user can select a date range. With plain old Redux, you need to do two steps:\n\n1. Isolate state in `calendarReducer` for particular instance of the Calendar\n2. Tag all the outgoing actions in `Calendar` component by id of the Calendar\n\n`prism` ensures that these points are a breeze. Both of the points in particular are nothing but function composition.\n\n`prism` is useful when you need to instantiate or isolate a UI component, where the UI component is defined as pair of View (React component) and correpsonding State (Redux Reducer).\n\n## Installation \u0026 Usage\nYou can install `prism` via npm.\n\n```\nnpm install prism --save\n```\n\nThe only peer dependency is React. Install `react` as well if you haven't done that yet.\n\n## Examples\n\nFor now, there's just one example showing action composition in action:\n\n1. [Counters Pair](./examples/counters)\n\n## Inspiration\n\nThis project was previously called `redux-elm` and you should still be able to see how those ideas evoled over time in git history. So significiant amount of inspiration has been drawn from [The Elm Architecture](https://guide.elm-lang.org/architecture/)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalsita%2Fprism","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsalsita%2Fprism","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalsita%2Fprism/lists"}