Philip // The Bakery - @bakeryhq
src/actions/index.js
export const RESET_ERROR_MESSAGE = 'RESET_ERROR_MESSAGE'
// Resets the currently visible error message.
export const resetErrorMessage = () => ({
type: RESET_ERROR_MESSAGE
})
src/reducers/index.js
⚡ import * as ActionTypes from '../actions'
import paginate from './paginate'
import { routerReducer as routing } from 'react-router-redux'
import { combineReducers } from 'redux'
🔧const entities = (state = { users: {}, repos: {} }, action) => {
return state
}
/* more reducers defined here */
const rootReducer = combineReducers({ entities, pagination })
export default rootReducer
src/containers/UserPage.js
import { ⚡loadUser, ⚡loadStarred } from '../actions'
class UserPage extends Component { /* stuff here */ }
const mapStateToProps = (state, ownProps) => {
const {
pagination: { starredByUser },
entities: { users, repos }
} = state
const starredRepos = starredPagination.ids.map(id => repos[id])
return { starredRepos }
}
export default connect(mapStateToProps, { ⚡loadUser, ⚡loadStarred })(UserPage)
app/containers/App/actions.js
import {
LOAD_REPOS,
LOAD_REPOS_SUCCESS,
LOAD_REPOS_ERROR,
} from './constants';
export function ⚡loadRepos() {
return {
type: LOAD_REPOS,
};
}
app/containers/App/reducer.js
import {
LOAD_REPOS_SUCCESS,
LOAD_REPOS,
LOAD_REPOS_ERROR,
} from './constants';
function 🔧appReducer(state = initialState, action) {
return state;
}
export default appReducer;
app/containers/App/selector.js
import { createSelector } from 'reselect';
const selectGlobal = () => (state) => state.get('global');
const 🍴selectCurrentUser = () => createSelector(
selectGlobal(),
(globalState) => globalState.get('currentUser')
);
export {
🍴selectGlobal,
🍴selectCurrentUser
};
app/containers/HomePage/index.js
import { 🍴selectRepos } from 'containers/App/selectors';
export class Page extends React.PureComponent {}
export function mapDispatchToProps(dispatch) {
return {
onChange: (evt) => dispatch(⚡changeUsername(evt.target.value))
};
};
const mapStateToProps = createStructuredSelector({
repos: 🍴selectRepos()
});
export default connect(mapStateToProps, mapDispatchToProps)(Page);
client/state/posts/actions.js
import {
POSTS_RECEIVE,
POSTS_REQUEST,
POSTS_REQUEST_SUCCESS,
POSTS_REQUEST_FAILURE
} from 'state/action-types';
export function ⚡receivePosts( posts ) {
return {
type: POSTS_RECEIVE,
posts
};
}
client/state/posts/reducer.js
import {
POSTS_REQUEST,
POSTS_REQUEST_SUCCESS,
POSTS_REQUEST_FAILURE
} from 'state/action-types';
export function 🔧siteRequests( state = {}, action ) {
return state;
}
client/state/posts/selectors.js
import createSelector from 'lib/create-selector';
export const 🍴getNormalizedPost = createSelector(
(state, globalId) => normalizePost(getPost(state, globalId)),
(state) => [state.posts.items, state.posts.queries]
);
client/components/data/query-geo/index.jsx
import { 🍴isRequestingGeo } from 'state/geo/selectors';
import { ⚡requestGeo } from 'state/geo/actions';
class QueryGeo extends Component {}
export default connect(
( state ) => ( { requesting: 🍴isRequestingGeo( state ) } ),
{ ⚡requestGeo }
)( QueryGeo );
source: graphql.org
ui/routes/FeedPage.js
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
class FeedPage extends React.Component { }
const FEED_QUERY = gql`
query Feed($type: FeedType!, $offset: Int, $limit: Int) {
feed(type: $type, offset: $offset, limit: $limit) {
...FeedEntry
}
}
`;
const withData = graphql(FEED_QUERY, { /* ... */ });
export default withData(FeedPage);