Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add babel-plugin-lodash for smaller bundles #228

Merged
merged 1 commit into from
Apr 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"es2015",
"react",
"stage-1"
],
"plugins": [
"lodash"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the babel plugin.

]
}
16 changes: 8 additions & 8 deletions docs/app/Components/Sidebar/Sidebar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash'
import _ from 'lodash/fp'
import React, { Component } from 'react'
import * as stardust from 'stardust'
import META from 'src/utils/Meta'
Expand All @@ -11,23 +11,23 @@ export default class Sidebar extends Component {
handleSearchChange = e => this.setState({ query: e.target.value })

getComponentsByQuery() {
return _.filter(stardust, component => {
return _.filter(component => {
const name = component._meta.name
const isParent = META.isParent(component)
const isQueryMatch = new RegExp(this.state.query, 'i').test(name)
return isParent && isQueryMatch
})
}, stardust)
}

getComponentsByType = type => {
const items = _(this.getComponentsByQuery())
.filter(component => META.isType(component, type))
.sortBy((component, name) => name)
.map(component => {
const items = _.flow(
_.filter(component => META.isType(component, type)),
_.sortBy((component, name) => name),
_.map(component => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chaining is not supported, this was the one place we used it. Refactored to use lodash/fp now with _.flow.

This is simply composing functions.

const name = component._meta.name
return <Menu.Item key={name} name={name} href={`#${name}`} />
})
.value()
)(this.getComponentsByQuery())

return _.isEmpty(items) ? [] : (
<div className='item'>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"babel-core": "^6.5.2",
"babel-eslint": "^4.1.6",
"babel-loader": "^6.2.0",
"babel-plugin-lodash": "^2.3.0",
"babel-plugin-react-transform": "^2.0.2",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
Expand Down