Skip to content

Instantly share code, notes, and snippets.

@queckezz
Last active December 8, 2015 10:22
Show Gist options
  • Save queckezz/7b81b5f1c68ebb5d2015 to your computer and use it in GitHub Desktop.
Save queckezz/7b81b5f1c68ebb5d2015 to your computer and use it in GitHub Desktop.
css in js
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
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.')
])
])
}
}
// 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'
}
}
// configureStyle.js
import styles from './styles'
const configureStyle = dispatch => zyle(dispatch, styles)
export default configureStyle
import styles from './2_1'
const style = mergeAll([
contain(40),
background('primary')
])
const Container = () => h('div', { style })
// 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