Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/felixschl/purescript-redux-saga
Manageable I/O for Purescript apps - http://slides.com/felixschl/managing-io-in-purescript
https://github.com/felixschl/purescript-redux-saga
purescript react redux saga
Last synced: 10 days ago
JSON representation
Manageable I/O for Purescript apps - http://slides.com/felixschl/managing-io-in-purescript
- Host: GitHub
- URL: https://github.com/felixschl/purescript-redux-saga
- Owner: felixSchl
- Created: 2017-08-23T17:33:00.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-06T17:08:16.000Z (over 6 years ago)
- Last Synced: 2024-10-11T23:54:30.384Z (27 days ago)
- Topics: purescript, react, redux, saga
- Language: PureScript
- Homepage:
- Size: 74.2 KB
- Stars: 20
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# purescript-redux-saga
Redux-saga inspired library for dealing with I/O in Purescript apps. The idea
is to completely isolate all I/O from pure code, meaning that neither the
reducer, nor the components, nor the action creators do _any_ kind of I/O
leaving the application mostly pure and placing all I/O into a single location.To do so, purescript-redux-saga creates a virtual thread of execution whose
inputs are either actions produced by the UI or attached Sagas, or values
received through "channels".# API Docs
API documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-redux-saga).
## Usage Example
``` purescript
-- Types.purs
type GlobalState = {}
data Action
= LoginRequest { username :: String, password :: String }
| LoginFailure Error
| LoginSuccess { username :: String, token :: String }-- Sagas.purs - Perform *all* I/O your app does here
saga :: ∀ env. Saga env Action GlobalState Unit
saga = forever do
take case _ of
LoginRequest { username, password } -> Just do
liftAff (attempt $ authenticate username password) >>= case _ of
Left err -> put $ LoginFailure err
Right token -> put $ LoginSuccess { username, token }
_ -> Nothing-- Store.purs - Install the Saga middleware
mkStore
:: ∀ eff
. Eff (ReduxEffect _)
(ReduxStore _ GlobalState Action)
mkStore = Redux.createStore reducer initialState middlewareEnhancer
where
initialState = {}
middlewareEnhancer = Redux.applyMiddleware
[ loggerMiddleware
, sagaMiddleware saga
]-- Main.purs - Tie the bow
main :: ∀ e. Eff _ Unit
main = do
store <- mkStore
Redux.createProviderElement store [ Redux.createElement_ appClass [] ]
```For a fully worked example, have a look at [purescript-redux-saga-example](https://github.com/felixschl/purescript-redux-saga-example).