Recompose Base Fiddle
Starting point for creating JSFiddles with Recompose. Forked from React Base Fiddle.
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script>
<script src="https://fb.me/react-with-addons-15.0.1.js"></script>
<script src="https://fb.me/react-dom-15.0.1.js"></script>
<script src="https://npmcdn.com/[email protected]/build/Recompose.js"></script>
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.22.1/ramda.min.js"></script>
<script src="https://npmcdn.com/[email protected]"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
JavaScript 1.7
// DON'T LOOK HERE SCROL UNTILL END COMMENT
// THESE ARE DEPS
const {isFunction, identity, isNil, isSymbol} = _;
function createAction(type, payloadCreator, metaCreator) {
const finalPayloadCreator = typeof payloadCreator === 'function'
? payloadCreator
: identity;
const actionHandler = (...args) => {
const hasError = args[0] instanceof Error;
const action = {
type
};
const payload = hasError ? args[0] : finalPayloadCreator(...args);
if (!(payload === null || payload === undefined)) {
action.payload = payload;
}
if (hasError) {
// Handle FSA errors where the payload is an Error object. Set error.
action.error = true;
}
if (typeof metaCreator === 'function') {
action.meta = metaCreator(...args);
}
return action;
};
actionHandler.toString = () => type;
return actionHandler;
}
function handleAction(type, reducers, defaultState) {
const typeValue = isSymbol(type)
? type
: type.toString();
const [nextReducer, throwReducer] = isFunction(reducers)
? [reducers, reducers]
: [reducers.next, reducers.throw].map(reducer => (isNil(reducer) ? identity : reducer));
return (state = defaultState, action) => {
if (action.type !== typeValue) {
return state;
}
return (action.error === true ? throwReducer : nextReducer)(state, action);
};
}
function reduceReducers(...reducers) {
return (previous, current) =>
reducers.reduce(
(p, r) => r(p, current),
previous
);
}
function ownKeys(object) {
if (typeof Reflect !== 'undefined' && typeof Reflect.ownKeys === 'function') {
return Reflect.ownKeys(object);
}
let keys = Object.getOwnPropertyNames(object);
if (typeof Object.getOwnPropertySymbols === 'function') {
keys = keys.concat(Object.getOwnPropertySymbols(object));
}
return keys;
}
function handleActions(handlers, defaultState) {
const reducers = ownKeys(handlers).map(type => handleAction(type,...