Last active
December 8, 2015 10:22
-
-
Save queckezz/7b81b5f1c68ebb5d2015 to your computer and use it in GitHub Desktop.
css in js
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 { | |
em | |
} from './utils' | |
import zyle from 'zyle' | |
function initStyles(dispatch) { | |
const gen = zyle(dispatch) | |
function contain (width = 56) { | |
return gen({ | |
max-width: em(containerWidth), | |
overflow: 'hidden' | |
}) | |
} | |
function displayFlex () { | |
// 1) Hash StyleObject -> '646efd54' | |
// 2) Check if classname is already in cache | |
// 3) Dispatch action to store { payload: { classname: '646efd54', styles: ... }} | |
// 4) Store renders style to client OR ANYTHING BRO | |
// 5) Return hash | |
return gen({ | |
display: 'flex' | |
}) | |
} | |
return { | |
contain, | |
displayFlex | |
} | |
} | |
export default initStyles | |
// importing | |
import initStyles from './styles' | |
const store = createStore() | |
const styles = initStyles(store.dispatch) | |
styles.contain(52) // -> 646efd54 |
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 from 'redux' | |
function contain (width) { | |
return { | |
max-width: em(width), | |
overflow: 'hidden' | |
} | |
} | |
function App () { | |
return h('div', { | |
style: mergeAll([ | |
contain(32), | |
colors(colors.BLUE) | |
], [ | |
h1('Some Text!'), | |
h2('An undertitle.') | |
]) | |
]) | |
} | |
} |
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
// styles.js | |
import { em } from 'redux-style' | |
import { dispatch } from './store' | |
function contain (width = 56) { | |
return { | |
max-width: em(containerWidth), | |
overflow: 'hidden' | |
} | |
} | |
function displayFlex () { | |
return { | |
display: 'flex' | |
} | |
} |
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
// configureStyle.js | |
import styles from './styles' | |
const configureStyle = dispatch => zyle(dispatch, styles) | |
export default configureStyle |
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 styles from './2_1' | |
const style = mergeAll([ | |
contain(40), | |
background('primary') | |
]) | |
const Container = () => h('div', { style }) |
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
// main.js | |
import configureStyle from './configureStyle' | |
import { stylesMiddleware as styles } from './zyle' | |
const store = applyMiddleWare( | |
...others, | |
stylesMiddleware() | |
) | |
const styles = configureStyle(store.dispatch) | |
render() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment