Skip to content

Commit

Permalink
Reduce svgs/index.js size 10%
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneLem committed Nov 9, 2017
1 parent c4c2584 commit cecb92b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 52 deletions.
21 changes: 17 additions & 4 deletions src/components/anchors.js
Expand Up @@ -7,9 +7,7 @@ export default class Anchors extends React.PureComponent {
constructor(props) {
super(props)

const { categories } = props

const defaultCategory = categories.filter(category => category.first)[0]
let defaultCategory = props.categories.filter(category => category.first)[0]

this.state = {
selected: defaultCategory.name,
Expand All @@ -18,6 +16,21 @@ export default class Anchors extends React.PureComponent {
this.handleClick = this.handleClick.bind(this)
}

getSVG(name) {
this.SVGs || (this.SVGs = {})

if (this.SVGs[name]) {
return this.SVGs[name]
} else {
let svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
${SVGs[name]}
</svg>`

this.SVGs[name] = svg
return svg
}
}

handleClick(e) {
var index = e.currentTarget.getAttribute('data-index')
var { categories, onAnchorClick } = this.props
Expand Down Expand Up @@ -50,7 +63,7 @@ export default class Anchors extends React.PureComponent {
: ''}`}
style={{ color: isSelected ? color : null }}
>
<div dangerouslySetInnerHTML={{ __html: SVGs[name] }} />
<div dangerouslySetInnerHTML={{ __html: this.getSVG(name) }} />
<span
className="emoji-mart-anchor-bar"
style={{ backgroundColor: color }}
Expand Down
67 changes: 19 additions & 48 deletions src/svgs/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cecb92b

Please sign in to comment.