{"size": 1452, "ext": "js", "max_stars_repo_path": "styles/getContext.js", "max_stars_repo_name": "MacKentoch/react-redux-nextjs-material-ui-pwa-starter", "max_stars_repo_stars_event_min_datetime": "2017-12-08T06:16:52.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-27T09:58:20.000Z", "max_issues_repo_path": "styles/getContext.js", "max_issues_repo_name": "MacKentoch/react-redux-nextjs-material-ui-pwa-starter", "max_issues_repo_issues_event_min_datetime": "2018-01-14T03:22:57.000Z", "max_issues_repo_issues_event_max_datetime": "2019-02-28T05:10:53.000Z", "max_forks_repo_path": "styles/getContext.js", "max_forks_repo_name": "MacKentoch/react-redux-nextjs-material-ui-pwa-starter", "max_forks_repo_forks_event_min_datetime": "2018-03-03T00:28:35.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-17T12:48:07.000Z"}
{"max_stars_count": 33, "max_issues_count": 3, "max_forks_count": 7, "avg_line_length": 25.9285714286, "max_line_length": 82, "alphanum_fraction": 0.6701101928}
// @flow

// region imports
import {
  create,
  SheetsRegistry
}                               from 'jss';
import preset                   from 'jss-preset-default';
import { createMuiTheme }       from 'material-ui/styles';
import createGenerateClassName  from 'material-ui/styles/createGenerateClassName';
import blue                     from 'material-ui/colors/blue';
import yellow                   from 'material-ui/colors/yellow';
// #endregion

// #region Mui theme configuration:
const theme = createMuiTheme({
  palette: {
    primary: blue,
    secondary: yellow
  }
});
// #endregion

// #region Configure JSS
const jss = create(preset());
jss.options.createGenerateClassName = createGenerateClassName;

function createContext() {
  return {
    jss,
    theme,
    // This is needed in order to deduplicate the injection of CSS in the page.
    sheetsManager: new Map(),
    // This is needed in order to inject the critical CSS.
    sheetsRegistry: new SheetsRegistry(),
  };
}
// #endregion

// #region jss store
export default function getContext() {
  // Make sure to create a new store for every server-side request so that data
  // isn't shared between connections (which would be bad)
  if (!process.browser) {
    return createContext();
  }

  // Reuse context on the client-side
  if (!global.__INIT_MATERIAL_UI__) {
    global.__INIT_MATERIAL_UI__ = createContext();
  }

  return global.__INIT_MATERIAL_UI__;
}
// #endregion
