Skip to content

Instantly share code, notes, and snippets.

@alyssaBiasi
alyssaBiasi / safeMapStateToProps.js
Created September 6, 2016 23:43
REA ReactJS Performance Debugging "State to Props with Reselect"
const mapStateToProps = (state) => ({
viewModel: getViewModel(state)
});
@alyssaBiasi
alyssaBiasi / unsafeMapStateToProps.js
Created September 6, 2016 22:53
REA ReactJS Performance Debugging "The Culprit"
const mapStateToProps = ({ filters }) => ({
viewModel: new ViewModel(filters.channel, filters.filters, filters.sortType)
});
@alyssaBiasi
alyssaBiasi / getViewModelSelector.js
Created September 6, 2016 22:51
REA ReactJS Performance Debugging "Selectors"
const { createSelector } = require('reselect');
export const getViewModel = createSelector(
[
getFiltersChannel,
getFilters,
getFiltersSort
],
(channel, filters, sortType) => new ViewModel(channel, filters, sortType)
);
@alyssaBiasi
alyssaBiasi / whyYouUpdate.js
Created September 6, 2016 22:19
REA ReactJS Performance Debugging "WhyYouUpdate Higher Order Component"
const WhyYouUpdate = Component => {
class WhyYouUpdate extends React.Component {
componentDidUpdate(prevProps, prevState) {
deepDiff(
{ props: prevProps, state: prevState },
{ props: this.props, state: this.state },
Component.displayName
);
}
@alyssaBiasi
alyssaBiasi / SearchBarContainer.js
Last active September 9, 2016 03:43
REA ReactJS Performance Debugging "Connecting with View Models"
const SearchBarContainer = ({ viewModel }) => ( ... );
const mapStateToProps = ({ filters }) => ({
viewModel: new ViewModel(filters.channel, filters.filters, filters.sortType)
});
export default connect(mapStateToProps)(SearchBarContainer);
@alyssaBiasi
alyssaBiasi / FirstConnectedComponent.js
Last active September 6, 2016 22:16
REA ReactJS Performance Debugging "Connecting"
const Component = ({ shouldRenderFeature }) => ( ... );
const mapStateToProps = (state) => ({
shouldRenderFeature: state.toggles.featureA
});
export default connect(mapStateToProps)(Component);
export default function featureToggles(state={}, action) {
switch (action.type) {
case Actions.FEATURE_TOGGLES_UPDATED:
return { ...state, ...action.data };
default:
return state;
}
}

It's not the cookies!! \o/

TL;DR: The flux stores are not being initialised on every request.

First request to the server:

request cookies:  {}
params:  {}
toggles: {}
class FeatureToggleStore extends MapStore {
getInitialState() {
return { featureToggles: {} };
}
reduce(state, payload) {
const { action } = payload;
switch (action.type) {
case Actions.FEATURE_TOGGLES_UPDATED:
const featureToggles = {