Beginning React+Redux "Music Store" sample

This commit is contained in:
SteveSandersonMS
2016-02-05 23:28:13 +00:00
parent 35e620ae48
commit 5811c98230
69 changed files with 7508 additions and 6 deletions

View File

@@ -0,0 +1,41 @@
import * as React from 'react';
import { Link } from 'react-router';
import { provide } from '../../TypedRedux';
import { ApplicationState } from '../../store';
import * as GenreList from '../../store/GenreList';
class Genres extends React.Component<GenresProps, void> {
componentWillMount() {
if (!this.props.genres.length) {
this.props.requestGenresList();
}
}
public render() {
let { genres } = this.props;
return <div>
<h3>Browse Genres</h3>
<p>Select from { genres.length || '...' } genres:</p>
<ul className="list-group">
{genres.map(genre =>
<li key={ genre.GenreId } className="list-group-item">
<Link to={ '/genre/' + genre.GenreId }>
{ genre.Name }
</Link>
</li>
)}
</ul>
</div>;
}
}
// Selects which part of global state maps to this component, and defines a type for the resulting props
const provider = provide(
(state: ApplicationState) => state.genreList,
GenreList.actionCreators
);
type GenresProps = typeof provider.allProps;
export default provider.connect(Genres);