Skip to content

Commit

Permalink
refactor: flatten profile state #21
Browse files Browse the repository at this point in the history
  • Loading branch information
1ambda committed Feb 27, 2016
1 parent bf34bdf commit b2be388
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
21 changes: 13 additions & 8 deletions app/src/containers/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// This file bootstraps the app with the boilerplate necessary
// to support hot reloading in Redux
import React from 'react'
import { bindActionCreators, } from 'redux'
import { connect, } from 'react-redux'
Expand All @@ -19,8 +17,7 @@ class App extends React.Component {
}

render() {
const { profile, actions, } = this.props
const { user, languages, repositories, activities, _$meta, } = profile
const { actions, meta, user, languages, repositories, activities, } = this.props

return (
<div className={css.container}>
Expand All @@ -32,15 +29,19 @@ class App extends React.Component {
repositories={repositories}
activities={activities} />
</div>
<Footer user={user} meta={_$meta} />
<Footer user={user} meta={meta} />
</div>
)
}
}

function mapStateToProps(state) {
return {
profile: state.profile,
return { /** flatten profile */
meta: state.profile.meta,
user: state.profile.user,
languages: state.profile.languages,
repositories: state.profile.repositories,
activities: state.profile.activities,
}
}

Expand All @@ -57,5 +58,9 @@ export default connect(

App.propTypes = {
actions: React.PropTypes.object.isRequired,
profile: React.PropTypes.object.isRequired,
meta: React.PropTypes.object.isRequired,
user: React.PropTypes.object.isRequired,
languages: React.PropTypes.array.isRequired,
repositories: React.PropTypes.array.isRequired,
activities: React.PropTypes.array.isRequired,
}
4 changes: 2 additions & 2 deletions app/src/reducers/ProfileReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as ActionTypes from '../actions/ActionTypes'

const initialState = {
user: {},
_$meta: {},
meta: {},
activities: [],
repositories: [],
languages: [],
Expand All @@ -27,7 +27,7 @@ export default function profileReducer(state = initialState, action = null) {

return Object.assign({}, state, {
user: payload.user,
_$meta: payload._$meta,
meta: payload._$meta,
activities: filteredActivities,
repositories: payload.repositories,
languages: payload.languages,
Expand Down
4 changes: 2 additions & 2 deletions bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bundle.js.map

Large diffs are not rendered by default.

0 comments on commit b2be388

Please sign in to comment.