Last active
December 2, 2015 18:59
-
-
Save queckezz/009017e4e86fd927d87f to your computer and use it in GitHub Desktop.
react better createElement (temporary until r-dom)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createElement } from 'react' | |
const isChildren = arr => typeof arr == 'string' || Array.isArray(arr) | |
const create = (tag, props, children) => { | |
if (Array.isArray(children)) { | |
return createElement(tag, props, ...children) | |
} else { | |
return createElement(tag, props, children) | |
} | |
} | |
const h = (tag, ...rest) => { | |
const [props, children] = rest | |
// h(tag, {}) or h(tag, []) | |
if (rest.length == 1) { | |
if (isChildren(props)) { | |
// children = props | |
return create(tag, {}, props) | |
} | |
return createElement(tag, props) | |
} | |
// all params h(tag, {}, []) | |
return create(tag, props, children) | |
} | |
export default h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
createStore, | |
applyMiddleware | |
} from 'redux' | |
import logger from 'redux-logger' | |
const createStoreWithMiddleware = applyMiddleware( | |
logger() | |
)(createStore) | |
export default createStoreWithMiddleware |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment