Skip to content

Instantly share code, notes, and snippets.

@andreystarkov
Created June 4, 2019 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreystarkov/7297d258d700f694beab68d838d199b9 to your computer and use it in GitHub Desktop.
Save andreystarkov/7297d258d700f694beab68d838d199b9 to your computer and use it in GitHub Desktop.
import { createReducer, createActions } from 'reduxsauce'
import Immutable from 'seamless-immutable'
import { sizes } from 'Themes/Media'
const { Types, Creators } = createActions({
layoutSetWidth: ['width']
})
export const LayoutTypes = Types
export default Creators
const defaults = {
isMobile: false,
isTablet: false,
isDeskop: false
}
export const getLayoutParams = ({ width }) => {
switch (width) {
case width <= sizes.s:
return { ...defaults, isMobile: true }
case width <= sizes.m:
return { ...defaults, isTablet: true }
case width > sizes.m:
return { ...defaults, isDesktop: true }
default:
return defaults
}
}
const LAYOUT_INITIAL_STATE = {
...getLayoutParams({ width: window.innerWidth }) // определяем значения при старте
}
export const layoutSetWidth = (state, { width }) => state.merge(getLayoutParams({ width }))
export const INITIAL_STATE = Immutable(LAYOUT_INITIAL_STATE)
export const reducers = createReducer(INITIAL_STATE, {
[Types.LAYOUT_SET_WIDTH]: layoutSetWidth
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment