This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 248
Pass custom store enhancer and middleware to redux store #93
Labels
Comments
Two things:
|
Allow 2 extra args in createStore function: A proof of concept // https://github.com/MoOx/statinamic/blob/master/src/redux/createStore/index.js#L4
import { createStore, applyMiddleware, compose } from "redux"
import thunk from "redux-thunk"
export default function(reducer = {}, initialState = {}, extraMiddlewares = {}, storeEnhancers = {}) {
function promiseMiddleware() {
return (next) => (action) => {
const { promise, types, ...rest } = action
if (!promise) {
return next(action)
}
else if (!promise.then) {
throw new Error(
"promiseMiddleware expects a promise object that implements then()"
)
}
const [ REQUEST, SUCCESS, FAILURE ] = types
next({ ...rest, type: REQUEST })
return promise.then(
(response) => next({ ...rest, response, type: SUCCESS }),
(error) => next({ ...rest, error, type: FAILURE })
)
}
}
let finalCreateStore
if (__DEVTOOLS__) {
const { devTools, persistState } = require("redux-devtools")
finalCreateStore = compose(
applyMiddleware(promiseMiddleware, thunk, ...extraMiddlewares),
devTools(),
persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/)),
...storeEnhancers
)(createStore)
}
else {
finalCreateStore = applyMiddleware(promiseMiddleware, thunk)(createStore)
}
return finalCreateStore(reducer, initialState)
}
```js |
Well, why not. |
Close ba16912 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Some basic function that I could build when statinamic have this feature:
I could send a PR for this. But I'm waiting for #91
The text was updated successfully, but these errors were encountered: