https://github.com/sliptype/react-pure
❄️ An example of managing state using Purescript in a React app
https://github.com/sliptype/react-pure
functional-programming purescript react
Last synced: 15 days ago
JSON representation
❄️ An example of managing state using Purescript in a React app
- Host: GitHub
- URL: https://github.com/sliptype/react-pure
- Owner: sliptype
- Created: 2018-06-27T02:43:58.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-17T00:07:24.000Z (about 7 years ago)
- Last Synced: 2025-10-09T15:38:42.906Z (15 days ago)
- Topics: functional-programming, purescript, react
- Language: JavaScript
- Homepage:
- Size: 230 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# react-pure
This is an example of using Purescript to handle business logic in a React + Redux application. It was created with `create-react-app`. It uses `purs-loader` to incorporate Purescript compilation into the webpack build.
# Advantages
* All the benefits of static-typing, purity, and controlled effects
* Redux debug tools
* JS ecosystem and tooling
# Setup
The actions, state, and reducers are written in Purescript. They can be found in the `state` directory.
Connecting this to Redux is done in `state/store.js`:
* `reducer` catches the initialization case, where `state` is undefined, by calling the `rootReducer` with an `Initial` value.
* `middleware` intercepts incoming actions to assign them a name (following "flux-standard-action")
# Dispatching
Each smart component has a corresponding `.purs` file that will handle mapping the state and dispatch to props. An example is `components/App.purs`, where the entire state is exposed as props and two actions are exposed to dispatch.
Action creators would be placed in their corresponding `actions.purs` file and they could be invoked inside `mapDispatchToProps`.