Update templates to domain-task 2.0.0. Fixes #166.

This commit is contained in:
SteveSandersonMS
2016-07-11 11:55:01 +01:00
parent fc897475f3
commit 58bf117442
9 changed files with 19 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
import { fetch } from 'domain-task/fetch'; import { fetch, addTask } from 'domain-task';
import { typeName, isActionType, Action, Reducer } from 'redux-typed'; import { typeName, isActionType, Action, Reducer } from 'redux-typed';
import { ActionCreator } from './'; import { ActionCreator } from './';
import { Genre } from './GenreList'; import { Genre } from './GenreList';
@@ -51,7 +51,7 @@ export const actionCreators = {
requestAlbumDetails: (albumId: number): ActionCreator => (dispatch, getState) => { requestAlbumDetails: (albumId: number): ActionCreator => (dispatch, getState) => {
// Only load if it's not already loaded (or currently being loaded) // Only load if it's not already loaded (or currently being loaded)
if (albumId !== getState().albumDetails.requestedAlbumId) { if (albumId !== getState().albumDetails.requestedAlbumId) {
fetch(`/api/albums/${ albumId }`) let fetchTask = fetch(`/api/albums/${ albumId }`)
.then(results => results.json()) .then(results => results.json())
.then(album => { .then(album => {
// Only replace state if it's still the most recent request // Only replace state if it's still the most recent request
@@ -60,6 +60,7 @@ export const actionCreators = {
} }
}); });
addTask(fetchTask); // Ensure server-side prerendering waits for this to complete
dispatch(new RequestAlbumDetails(albumId)); dispatch(new RequestAlbumDetails(albumId));
} }
} }

View File

@@ -1,4 +1,4 @@
import { fetch } from 'domain-task/fetch'; import { fetch, addTask } from 'domain-task';
import { typeName, isActionType, Action, Reducer } from 'redux-typed'; import { typeName, isActionType, Action, Reducer } from 'redux-typed';
import { ActionCreator } from './'; import { ActionCreator } from './';
@@ -39,10 +39,11 @@ class ReceiveFeaturedAlbums extends Action {
export const actionCreators = { export const actionCreators = {
requestFeaturedAlbums: (): ActionCreator => (dispatch, getState) => { requestFeaturedAlbums: (): ActionCreator => (dispatch, getState) => {
if (!getState().featuredAlbums.isLoaded) { if (!getState().featuredAlbums.isLoaded) {
fetch('/api/albums/mostPopular') let fetchTask = fetch('/api/albums/mostPopular')
.then(results => results.json()) .then(results => results.json())
.then(albums => dispatch(new ReceiveFeaturedAlbums(albums))); .then(albums => dispatch(new ReceiveFeaturedAlbums(albums)));
addTask(fetchTask); // Ensure server-side prerendering waits for this to complete
return dispatch(new RequestFeaturedAlbums()); return dispatch(new RequestFeaturedAlbums());
} }
} }

View File

@@ -1,4 +1,4 @@
import { fetch } from 'domain-task/fetch'; import { fetch, addTask } from 'domain-task';
import { typeName, isActionType, Action, Reducer } from 'redux-typed'; import { typeName, isActionType, Action, Reducer } from 'redux-typed';
import { ActionCreator } from './'; import { ActionCreator } from './';
import { Album } from './FeaturedAlbums'; import { Album } from './FeaturedAlbums';
@@ -39,7 +39,7 @@ export const actionCreators = {
requestGenreDetails: (genreId: number): ActionCreator => (dispatch, getState) => { requestGenreDetails: (genreId: number): ActionCreator => (dispatch, getState) => {
// Only load if it's not already loaded (or currently being loaded) // Only load if it's not already loaded (or currently being loaded)
if (genreId !== getState().genreDetails.requestedGenreId) { if (genreId !== getState().genreDetails.requestedGenreId) {
fetch(`/api/genres/${ genreId }/albums`) let fetchTask = fetch(`/api/genres/${ genreId }/albums`)
.then(results => results.json()) .then(results => results.json())
.then(albums => { .then(albums => {
// Only replace state if it's still the most recent request // Only replace state if it's still the most recent request
@@ -48,6 +48,7 @@ export const actionCreators = {
} }
}); });
addTask(fetchTask); // Ensure server-side prerendering waits for this to complete
dispatch(new RequestGenreDetails(genreId)); dispatch(new RequestGenreDetails(genreId));
} }
} }

View File

@@ -1,4 +1,4 @@
import { fetch } from 'domain-task/fetch'; import { fetch, addTask } from 'domain-task';
import { typeName, isActionType, Action, Reducer } from 'redux-typed'; import { typeName, isActionType, Action, Reducer } from 'redux-typed';
import { ActionCreator } from './'; import { ActionCreator } from './';
@@ -34,9 +34,10 @@ class ReceiveGenresList extends Action {
export const actionCreators = { export const actionCreators = {
requestGenresList: (): ActionCreator => (dispatch, getState) => { requestGenresList: (): ActionCreator => (dispatch, getState) => {
if (!getState().genreList.isLoaded) { if (!getState().genreList.isLoaded) {
fetch('/api/genres') let fetchTask = fetch('/api/genres')
.then(results => results.json()) .then(results => results.json())
.then(genres => dispatch(new ReceiveGenresList(genres))); .then(genres => dispatch(new ReceiveGenresList(genres)));
addTask(fetchTask); // Ensure server-side prerendering waits for this to complete
} }
} }
}; };

View File

@@ -25,7 +25,7 @@
"aspnet-webpack-react": "^1.0.1", "aspnet-webpack-react": "^1.0.1",
"bootstrap": "^3.3.6", "bootstrap": "^3.3.6",
"domain-context": "^0.5.1", "domain-context": "^0.5.1",
"domain-task": "^1.0.0", "domain-task": "^2.0.0",
"history": "^2.0.0", "history": "^2.0.0",
"isomorphic-fetch": "^2.2.1", "isomorphic-fetch": "^2.2.1",
"memory-fs": "^0.3.0", "memory-fs": "^0.3.0",

View File

@@ -4,7 +4,7 @@
"dependencies": { "dependencies": {
"babel-core": "^6.4.5", "babel-core": "^6.4.5",
"bootstrap": "^3.3.5", "bootstrap": "^3.3.5",
"domain-task": "^1.0.0", "domain-task": "^2.0.0",
"formsy-react": "^0.17.0", "formsy-react": "^0.17.0",
"formsy-react-components": "^0.6.3", "formsy-react-components": "^0.6.3",
"griddle-react": "^0.3.1", "griddle-react": "^0.3.1",

View File

@@ -1,4 +1,4 @@
import { fetch } from 'domain-task/fetch'; import { fetch, addTask } from 'domain-task';
import { typeName, isActionType, Action, Reducer } from 'redux-typed'; import { typeName, isActionType, Action, Reducer } from 'redux-typed';
import { ActionCreator } from './'; import { ActionCreator } from './';
@@ -45,12 +45,13 @@ export const actionCreators = {
requestWeatherForecasts: (startDateIndex: number): ActionCreator => (dispatch, getState) => { requestWeatherForecasts: (startDateIndex: number): ActionCreator => (dispatch, getState) => {
// Only load data if it's something we don't already have (and are not already loading) // Only load data if it's something we don't already have (and are not already loading)
if (startDateIndex !== getState().weatherForecasts.startDateIndex) { if (startDateIndex !== getState().weatherForecasts.startDateIndex) {
fetch(`/api/SampleData/WeatherForecasts?startDateIndex=${ startDateIndex }`) let fetchTask = fetch(`/api/SampleData/WeatherForecasts?startDateIndex=${ startDateIndex }`)
.then(response => response.json()) .then(response => response.json())
.then((data: WeatherForecast[]) => { .then((data: WeatherForecast[]) => {
dispatch(new ReceiveWeatherForecasts(startDateIndex, data)); dispatch(new ReceiveWeatherForecasts(startDateIndex, data));
}); });
addTask(fetchTask); // Ensure server-side prerendering waits for this to complete
dispatch(new RequestWeatherForecasts(startDateIndex)); dispatch(new RequestWeatherForecasts(startDateIndex));
} }
} }

View File

@@ -23,7 +23,7 @@
"aspnet-prerendering": "^1.0.2", "aspnet-prerendering": "^1.0.2",
"aspnet-webpack": "^1.0.2", "aspnet-webpack": "^1.0.2",
"babel-core": "^6.5.2", "babel-core": "^6.5.2",
"domain-task": "^1.0.0", "domain-task": "^2.0.0",
"react": "^15.0.1", "react": "^15.0.1",
"react-dom": "^15.0.1", "react-dom": "^15.0.1",
"react-redux": "^4.4.4", "react-redux": "^4.4.4",

View File

@@ -1,6 +1,6 @@
{ {
"name": "generator-aspnetcore-spa", "name": "generator-aspnetcore-spa",
"version": "0.2.1", "version": "0.2.2",
"description": "Single-Page App templates for ASP.NET Core", "description": "Single-Page App templates for ASP.NET Core",
"author": "Microsoft", "author": "Microsoft",
"license": "Apache-2.0", "license": "Apache-2.0",