This repository was archived by the owner on Feb 11, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +116
-4
lines changed Expand file tree Collapse file tree 5 files changed +116
-4
lines changed Original file line number Diff line number Diff line change
1
+
2
+ export const ADD_PRIME = 'ADD_PRIME' ;
3
+ export const ADD_NON_PRIME = 'ADD_PRIME' ;
4
+ export const QUEUE_NUMBER = 'QUEUE_NUMBER' ;
5
+
6
+ export function testPrime ( number ) {
7
+ return {
8
+ type : QUEUE_NUMBER ,
9
+ number
10
+ } ;
11
+ }
12
+
Original file line number Diff line number Diff line change
1
+ import React , { Component , PropTypes } from 'react' ;
2
+ import { connect } from 'react-redux' ;
3
+
4
+ class App extends Component {
5
+ constructor ( props ) {
6
+ super ( props ) ;
7
+ }
8
+
9
+ render ( ) {
10
+ return (
11
+ < div >
12
+ < h1 > redux-trigger simple example</ h1 >
13
+ </ div >
14
+ ) ;
15
+ }
16
+ }
17
+
18
+ App . propTypes = {
19
+ dispatch : PropTypes . func . isRequired
20
+ } ;
21
+
22
+ function mapStateToProps ( state ) {
23
+ return { } ;
24
+ }
25
+
26
+ export default connect ( mapStateToProps ) ( App ) ;
27
+
Original file line number Diff line number Diff line change 1
1
import 'babel-core/polyfill' ;
2
2
import React from 'react' ;
3
3
import { render } from 'react-dom' ;
4
+ import { Provider } from 'react-redux' ;
5
+ import App from './containers/App' ;
6
+ import configureStore from './store/configureStore' ;
4
7
5
- render (
6
- < h1 > Test</ h1 > ,
7
- document . getElementById ( 'root' )
8
- ) ;
8
+ const store = configureStore ( ) ;
9
+
10
+ const rootComponent =
11
+ < Provider store = { store } >
12
+ < App />
13
+ </ Provider > ;
14
+
15
+ render ( rootComponent , document . getElementById ( 'root' ) ) ;
9
16
Original file line number Diff line number Diff line change
1
+ import { combineReducers } from 'redux' ;
2
+ import {
3
+ ADD_PRIME ,
4
+ ADD_NON_PRIME ,
5
+ QUEUE_NUMBER
6
+ } from '../actions/primes' ;
7
+
8
+ const primesInitialState = {
9
+ primes : [ ] ,
10
+ nonPrimes : [ ] ,
11
+ queue : [ ]
12
+ } ;
13
+
14
+ function primesReducer ( state = primesInitialState , action ) {
15
+ switch ( action . type ) {
16
+ case ADD_PRIME :
17
+ const primes = [ ...state . primes , action . prime ] ;
18
+
19
+ return Object . assign ( { } , state , {
20
+ primes
21
+ } ) ;
22
+ case ADD_NON_PRIME :
23
+ const nonPrimes = [ ...state . nonPrimes , action . nonPrime ] ;
24
+
25
+ return Object . assign ( { } , state , {
26
+ nonPrimes
27
+ } ) ;
28
+ case QUEUE_NUMBER :
29
+ const queue = [ ...state . queue , action . number ] ;
30
+
31
+ return Object . assign ( { } , state , {
32
+ queue
33
+ } ) ;
34
+ default :
35
+ return state ;
36
+ }
37
+ }
38
+
39
+ const rootReducer = combineReducers ( {
40
+ primesReducer
41
+ } ) ;
42
+
43
+ export default rootReducer ;
44
+
Original file line number Diff line number Diff line change
1
+ import { createStore , applyMiddleware } from 'redux' ;
2
+ import createLogger from 'redux-logger' ;
3
+ import rootReducer from '../reducers' ;
4
+
5
+ const createStoreWithMiddleware = applyMiddleware (
6
+ createLogger ( )
7
+ ) ( createStore ) ;
8
+
9
+ export default function configureStore ( initialState ) {
10
+ const store = createStoreWithMiddleware ( rootReducer , initialState ) ;
11
+
12
+ if ( module . hot ) {
13
+ // Enable Webpack hot module replacement for reducers
14
+ module . hot . accept ( '../reducers' , ( ) => {
15
+ const nextRootReducer = require ( '../reducers' ) ;
16
+ store . replaceReducer ( nextRootReducer ) ;
17
+ } ) ;
18
+ }
19
+
20
+ return store ;
21
+ }
22
+
You can’t perform that action at this time.
0 commit comments