apache_conf 真实世界Ramda:配置您的Redux商店
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了apache_conf 真实世界Ramda:配置您的Redux商店相关的知识,希望对你有一定的参考价值。
[Real World Ramda: Readable Redux Stores](https://medium.com/p/2f8a92991646)
// client/store/enhancers/prod.js
import { applyMiddleware } from 'redux';
import { merge } from 'ramda';
import { browserHistory } from 'react-router';
import { routerMiddleware } from 'react-router-redux';
import thunkMiddleware from 'redux-thunk';
import { apiMiddleware } from 'redux-api-middleware';
import composeEnhancers, { defaultExtensionOptions } from 'client/store/devtools';
const extensionOptions = merge(defaultExtensionOptions, {
features: {
pause: true,
lock: true,
persist: true,
export: true,
jump: true,
skip: true,
reorder: true,
dispatch: true,
test: false
}
});
const composer = composeEnhancers(extensionOptions);
export default composer(
applyMiddleware(
thunkMiddleware,
apiMiddleware,
routerMiddleware(browserHistory)
)
);
// client/store/index.js
import configureStore from 'store/configureStore';
export default configureStore({});
// client/store/enhancers.js
let enhancer;
if (__DEVELOPMENT__) {
enhancer = require('./enhancers/dev').default;
} else if (__PRODUCTION__) {
enhancer = require('./enhancers/prod').default;
}
export default enhancer;
// client/store/devtools.js
import { curry, is, ifElse, allPass, isNil, not, identity } from 'ramda';
import { compose } from 'redux';
import { Iterable } from 'immutable';
const windowExists = is(Object, window);
const extensionCompose = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
const extensionComposeExists = not(isNil(extensionCompose));
const isImmutable = curry(Iterable.isIterable);
const serializeImmutable = value => value.toJS();
const defaultExtensionOptions = {
serialize: {
replacer: (key, value) => ifElse(
isImmutable,
serializeImmutable,
identity
)(value)
}
};
const composeEnhancers = curry((options = defaultExtensionOptions) => {
return ifElse(
allPass(windowExists, extensionComposeExists),
extensionCompose(options),
compose
);
});
export { composeEnhancers as default, defaultExtensionOptions };
// client/store/enhancers/dev.js
import { applyMiddleware } from 'redux';
import { persistState } from 'redux-devtools';
import { browserHistory } from 'react-router';
import { routerMiddleware } from 'react-router-redux';
import thunkMiddleware from 'redux-thunk';
import { apiMiddleware } from 'redux-api-middleware';
import composeEnhancers, { defaultExtensionOptions } from 'client/store/devtools';
const composer = composeEnhancers(defaultExtensionOptions);
export default composer(
applyMiddleware(
apiMiddleware,
thunkMiddleware,
routerMiddleware(browserHistory)
)
);
// client/store/configureStore.js
import { createStore } from 'redux';
import { compose, when, equals } from 'ramda';
import enhancer from 'client/store/enhancers';
import rootReducer from 'client/reducers';
function configureStore(initialState) {
const store = createStore(rootReducer, initialState, enhancer);
const addStoreToObj = obj => (obj.store = store);
const addStateToObj = obj => (obj.state = store.getState());
// compose our window utilities from above
const attachHelpersToWindow = compose(
addStoreToObj,
addStateToObj
)(window);
// attach state and our store to window in development
when(
equals(__DEVELOPMENT__, true),
attachHelpersToWindow
);
return store;
}
export default configureStore;
以上是关于apache_conf 真实世界Ramda:配置您的Redux商店的主要内容,如果未能解决你的问题,请参考以下文章
apache_conf Ramda&Redux(选择例子)
真实世界的 WebAssembly
带有 FP 类型的 Ramda
markdown 使用ramda通过嵌套值过滤对象数组:有时您无权访问后端,并且您希望过滤来自
apache_conf 基于Bourbon的SASS配置和调试选项导入配置文件后,您可以将bourbon称为@import“bourbon”
apache_conf Prepros配置用于使用全罗盘支持的站点。这允许您为所有内容设置导向器。