- blocks
- Screen
- Actions
- Screen-Actions.js
- Reducer
- Screen-Reducer.js
- Screen.js
- Actions
- Root
- Root.js
- Screen
- state
- index.js
- lib
- connector.js
Last active
January 31, 2017 18:14
-
-
Save awinogradov/e8f9ea51a9c44b6cc0ae911e3851c2ea to your computer and use it in GitHub Desktop.
Connect to state (bem-react-core)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { bindActionCreators } from 'redux'; | |
import { connect } from 'react-redux'; | |
export default function connectToState(inst) { | |
const Connected = connect(inst.stateToProps, dispatch => { | |
return { | |
...bindActionCreators(inst.actions || {}, dispatch), | |
dispatch | |
}; | |
})(inst); | |
return Connected; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createStore, applyMiddleware, compose, combineReducers } from 'redux'; | |
import thunk from 'redux-thunk'; | |
import Screen from 'b:Screen'; | |
const actionCreators = { | |
...Screen.actions | |
}; | |
const rootReducer = combineReducers({ | |
screen: Screen.reducer | |
}); | |
const enhancer = compose( | |
applyMiddleware(thunk), | |
window.devToolsExtension ? | |
window.devToolsExtension({ actionCreators }) : | |
noop => noop | |
); | |
export default function configureStore(initialState) { | |
const store = createStore(rootReducer, initialState, enhancer); | |
if (window.devToolsExtension) { | |
window.devToolsExtension.updateStore(store); | |
} | |
if (module.hot) { | |
store.replaceReducer(rootReducer); | |
} | |
return store; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { decl } from 'bem-react-core'; | |
import Screen from 'b:Screen'; | |
const СScreen = connect(Screen); | |
export default decl({ | |
block: 'Root', | |
content() { | |
return <СScreen />; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {createAction} from 'redux-actions'; | |
export const select = createAction('SELECT_SCREEN'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { handleActions } from 'redux-actions'; | |
export default handleActions({ | |
SELECT_SCREEN: (state, action) => ({ | |
name: action.payload | |
}) | |
}, {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { decl } from 'bem-react-core'; | |
import * as actions from './Actions/Screen-Actions'; | |
import reducer from './Reducer/Screen-Reducer'; | |
export default decl({ | |
block: 'Screen' | |
}, { | |
actions, | |
reducer, | |
stateToProps: state => ({ | |
current: state.screen.name | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment