File tree Expand file tree Collapse file tree 4 files changed +51
-10
lines changed Expand file tree Collapse file tree 4 files changed +51
-10
lines changed Original file line number Diff line number Diff line change
1
+ import * as types from 'constants/action-types' ;
2
+ export function fetchUngitConfig ( ) {
3
+ return dispatch => {
4
+ // consider wrap API call in separate modules
5
+ // it will be easy to stub module's function when testing
6
+ fetch ( 'http://localhost:8448/ungit/config' )
7
+ . then ( response => response . json ( ) )
8
+ . then ( json => {
9
+ dispatch ( receiveUgitConfig ( json ) ) ;
10
+ } ) ;
11
+ } ;
12
+ } ;
13
+
14
+ export function receiveUgitConfig ( ungitConfig ) {
15
+ return {
16
+ type : types . RECEIVE_UNGIT_CONFIG ,
17
+ ungitConfig
18
+ } ;
19
+ } ;
Original file line number Diff line number Diff line change
1
+ export const RECEIVE_UNGIT_CONFIG = 'RECEIVE_UNGIT_CONFIG' ;
Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react' ;
2
+ import { bindActionCreators } from 'redux' ;
2
3
import { connect } from 'react-redux'
3
4
5
+ import * as ungitConfigActionCreators from 'actions/ungit-config' ;
4
6
import 'styles/styles.scss' ;
5
7
6
- @connect ( state => { return { ...state } } )
8
+ @connect ( state => {
9
+ return { ...state } ;
10
+ } , dispatch => {
11
+ return {
12
+ actions : bindActionCreators ( Object . assign ( { } , ungitConfigActionCreators ) , dispatch )
13
+ } ;
14
+ } )
7
15
class Path extends Component {
16
+
17
+ componentWillMount ( ) {
18
+ const { actions } = this . props ;
19
+ actions . fetchUngitConfig ( ) ;
20
+ }
21
+
8
22
render ( ) {
9
23
return (
10
- < div className = "App" >
11
- < div className = "App-header" >
12
- < h2 > Welcome to { this . props . app } </ h2 >
24
+ < div >
25
+ < div className = "app-top-margin" > </ div >
26
+ < div className = "app-wrapper" >
27
+ < div className = "container" data-bind = "shown: shown" data-ta-container = "app" >
28
+ </ div >
13
29
</ div >
14
- < p className = "App-intro" >
15
- To get started, edit < code > src/container/Path.js</ code > and save to reload.
16
- </ p >
17
30
</ div >
18
31
) ;
19
32
}
Original file line number Diff line number Diff line change
1
+ import * as types from 'constants/action-types' ;
2
+
1
3
const initialState = {
2
- app : 'React'
4
+ ungitConfig : null
3
5
} ;
4
6
5
- const ungitApp = function ( state , action ) {
6
- return { ...initialState } ;
7
+ const ungitApp = function ( state = initialState , action ) {
8
+ switch ( action . type ) {
9
+ case types . RECEIVE_UNGIT_CONFIG :
10
+ const { ungitConfig } = action ;
11
+ return { ...state , ungitConfig } ;
12
+ default :
13
+ return { ...state } ;
14
+ }
7
15
}
8
16
9
17
export default ungitApp ;
You can’t perform that action at this time.
0 commit comments