Skip to content

Commit 25eb194

Browse files
committed
Breaking changes to speed up initialization.
Don't create styles striing or init components when creating Typography object Fixes #22
1 parent 9fa93d7 commit 25eb194

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/components/TypographyStyle.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ module.exports = (styles) ->
1313
React.DOM.style({
1414
id: "typography.js"
1515
dangerouslySetInnerHTML:
16-
__html: styles
16+
__html: styles()
1717
})

src/index.coffee

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@ React = require 'react'
22
objectAssign = require('object-assign')
33
VerticalRhythm = require 'compass-vertical-rhythm'
44
ms = require 'modularscale'
5-
isArray = require 'is-array'
65
isObject = require 'isobject'
76
copy = require 'shallow-copy'
87

98
createStyles = require('./utils/createStyles')
109

10+
createStylesString = (options) ->
11+
# Create styles for base theme + each subtheme.
12+
vr = VerticalRhythm(options)
13+
styles = createStyles(vr, options)
14+
15+
if options.subThemes? and isObject(options.subThemes)
16+
for name, theme of options.subThemes
17+
vr = VerticalRhythm(theme)
18+
styles += createStyles(vr, theme, name, options)
19+
20+
return styles
21+
1122
module.exports = test = (options) ->
1223
defaults =
1324
baseFontSize: '18px'
@@ -39,32 +50,22 @@ module.exports = test = (options) ->
3950
for name, theme of options.subThemes
4051
options.subThemes[name] = objectAssign(copy(options), theme, rhythmUnit: 'px')
4152

42-
unless isArray options.modularScales
43-
options.modularScales = [options.modularScales]
44-
45-
# Create styles for base theme + each subtheme.
4653
vr = VerticalRhythm(options)
47-
styles = createStyles(vr, options)
48-
49-
if options.subThemes? and isObject(options.subThemes)
50-
for name, theme of options.subThemes
51-
vr = VerticalRhythm(theme)
52-
styles += createStyles(vr, theme, name, options)
5354

5455
return {
5556
options: options
56-
GoogleFont: require('./components/GoogleFont')(options)
57-
TypographyStyle: require('./components/TypographyStyle')(styles)
57+
GoogleFont: -> require('./components/GoogleFont')(options)
58+
TypographyStyle: -> require('./components/TypographyStyle')(-> createStylesString(options))
5859
rhythm: vr.rhythm
59-
styles: styles
60+
createStyles: -> createStylesString(options)
6061
fontSizeToPx: vr.adjustFontSizeTo
6162
fontSizeToMS: (scaler) ->
6263
baseFont = options.baseFontSize.slice(0, -2)
6364
newFontSize = ms(scaler, options.modularScales[0]) * baseFont + "px"
6465
vr.adjustFontSizeTo(newFontSize)
6566
injectStyles: ->
6667
node = document.createElement('style')
67-
node.innerHTML = styles
68+
node.innerHTML = createStylesString()
6869
document.head.appendChild(node)
6970
}
7071

@@ -74,4 +75,4 @@ module.exports = test = (options) ->
7475
#blog:
7576
#baseFontSize: '18px'
7677
#bodyFontFamily: 'Open Sans'
77-
#}).styles
78+
#}).createStyles()

0 commit comments

Comments
 (0)