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,48 @@
import * as React from 'react';
import { Link } from 'react-router';
import { provide } from '../../TypedRedux';
import { ApplicationState } from '../../store';
import * as GenreDetailsStore from '../../store/GenreDetails';
import { AlbumTile } from './AlbumTile';
interface RouteParams {
genreId: number
}
class GenreDetails extends React.Component<GenreDetailsProps, void> {
componentWillMount() {
this.props.requestGenreDetails(this.props.params.genreId);
}
componentWillReceiveProps(nextProps: GenreDetailsProps) {
if (nextProps.params.genreId !== this.props.params.genreId) {
nextProps.requestGenreDetails(nextProps.params.genreId);
}
}
public render() {
if (this.props.isLoaded) {
let albums = this.props.albums;
return <div>
<h3>Albums</h3>
<ul className="list-unstyled">
{albums.map(album =>
<AlbumTile key={ album.AlbumId } album={ album } />
)}
</ul>
</div>;
} else {
return <p>Loading...</p>;
}
}
}
// Selects which part of global state maps to this component, and defines a type for the resulting props
const provider = provide(
(state: ApplicationState) => state.genreDetails,
GenreDetailsStore.actionCreators
).withExternalProps<{ params: RouteParams }>();
type GenreDetailsProps = typeof provider.allProps;
export default provider.connect(GenreDetails);