Skip to content
This repository was archived by the owner on Feb 11, 2021. It is now read-only.

Commit daa0a6c

Browse files
committed
Add NumberList component
This commit adds the NumberList component and shows it for Primes and Non-Primes It also renames the top-level "primes" state to "primeState" because it holds a compound state within it containing primes, non-primes, and a queue of not-yet-processed numbers.
1 parent 6b8b41e commit daa0a6c

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React, { Component, PropTypes } from 'react';
2+
3+
export default class NumberList extends Component {
4+
render() {
5+
const { numbers } = this.props;
6+
7+
return (
8+
<div>
9+
<ul>
10+
{
11+
numbers.map( ( value ) => {
12+
return <li>{ value }</li>;
13+
} )
14+
}
15+
</ul>
16+
</div>
17+
);
18+
}
19+
}
20+
21+
NumberList.propTypes = {
22+
numbers: PropTypes.array.isRequired
23+
};
24+

examples/simple/containers/App.jsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { Component, PropTypes } from 'react';
22
import { connect } from 'react-redux';
33
import NumberPicker from '../components/NumberPicker';
4+
import NumberList from '../components/NumberList';
45
import { setNumberEntry } from '../actions/numberentry';
56
import { addNumber } from '../actions/primes';
67

@@ -25,29 +26,38 @@ class App extends Component {
2526

2627
render() {
2728
const submitText = "Add Number";
28-
const { numberEntry } = this.props;
29+
const { numberEntry, primes, nonPrimes } = this.props;
2930

3031
return (
3132
<div>
3233
<NumberPicker submitText={ submitText }
3334
value={ numberEntry }
3435
onChange={ this.handleNumberEntryChange }
3536
onSubmit={ this.handleNumberEntrySubmit } />
37+
<h2>Primes</h2>
38+
<NumberList numbers={ primes } />
39+
<h2>Non-Primes</h2>
40+
<NumberList numbers={ nonPrimes } />
3641
</div>
3742
);
3843
}
3944
}
4045

4146
App.propTypes = {
4247
numberEntry: PropTypes.string.isRequired,
48+
primes: PropTypes.array.isRequired,
49+
nonPrimes: PropTypes.array.isRequired,
4350
dispatch: PropTypes.func.isRequired
4451
};
4552

4653
function mapStateToProps( state ) {
47-
const { numberEntry } = state;
54+
const { numberEntry, primeState } = state;
55+
const { primes, nonPrimes } = primeState;
4856

4957
return {
50-
numberEntry
58+
numberEntry,
59+
primes,
60+
nonPrimes
5161
};
5262
}
5363

examples/simple/reducers/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const primesInitialState = {
3232
queue: []
3333
};
3434

35-
function primes( state = primesInitialState, action ) {
35+
function primeState( state = primesInitialState, action ) {
3636
switch ( action.type ) {
3737
case ADD_PRIME:
3838
const primes = [ ...state.primes, action.prime ];
@@ -59,7 +59,7 @@ function primes( state = primesInitialState, action ) {
5959

6060
const rootReducer = combineReducers( {
6161
numberEntry,
62-
primes
62+
primeState
6363
} );
6464

6565
export default rootReducer;

0 commit comments

Comments
 (0)