Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit b09bb9e

Browse files
committed
Update ReactReduxSpa template to TypeScript 2.0
Based on MarkPieszak's edits
1 parent 5cacdec commit b09bb9e

31 files changed

+112
-4408
lines changed

templates/ReactReduxSpa/ClientApp/components/FetchData.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ interface RouteParams {
1111
class FetchData extends React.Component<WeatherForecastProps, void> {
1212
componentWillMount() {
1313
// This method runs when the component is first added to the page
14-
let startDateIndex = parseInt(this.props.params.startDateIndex) || 0;
14+
let startDateIndex = parseInt(this.props.params.startDateIndex, 10) || 0;
1515
this.props.requestWeatherForecasts(startDateIndex);
1616
}
1717

1818
componentWillReceiveProps(nextProps: WeatherForecastProps) {
1919
// This method runs when incoming props (e.g., route params) change
20-
let startDateIndex = parseInt(nextProps.params.startDateIndex) || 0;
20+
let startDateIndex = parseInt(nextProps.params.startDateIndex, 10) || 0;
2121
this.props.requestWeatherForecasts(startDateIndex);
2222
}
2323

Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
import { createStore, applyMiddleware, compose, combineReducers } from "redux";
2-
import * as thunkModule from "redux-thunk";
1+
import * as Redux from "redux";
2+
import { createStore, applyMiddleware, compose, combineReducers, GenericStoreEnhancer } from "redux";
3+
import thunk from "redux-thunk";
34
import { routerReducer } from "react-router-redux";
45
import * as Store from "./store";
56
import { typedToPlain } from "redux-typed";
67

8+
79
export default function configureStore(initialState?: Store.ApplicationState) {
810
// Build middleware. These are functions that can process the actions before they reach the store.
9-
const thunk = (thunkModule as any).default; // Workaround for TypeScript not importing thunk module as expected
1011
const windowIfDefined = typeof window === "undefined" ? null : window as any;
11-
const devToolsExtension = windowIfDefined && windowIfDefined.devToolsExtension; // If devTools is installed, connect to it
12+
// If devTools is installed, connect to it
13+
const devToolsExtension = windowIfDefined && windowIfDefined.devToolsExtension as () => GenericStoreEnhancer;
1214
const createStoreWithMiddleware = compose(
1315
applyMiddleware(thunk, typedToPlain),
1416
devToolsExtension ? devToolsExtension() : f => f
1517
)(createStore);
1618

1719
// Combine all reducers and instantiate the app-wide store instance
1820
const allReducers = buildRootReducer(Store.reducers);
19-
const store = createStoreWithMiddleware(allReducers, initialState) as Redux.Store;
21+
const store = createStoreWithMiddleware(allReducers, initialState) as Redux.Store<Store.ApplicationState>;
2022

2123
// Enable Webpack hot module replacement for reducers
2224
if (module.hot) {
@@ -30,5 +32,5 @@ export default function configureStore(initialState?: Store.ApplicationState) {
3032
}
3133

3234
function buildRootReducer(allReducers) {
33-
return combineReducers(Object.assign({}, allReducers, { routing: routerReducer })) as Redux.Reducer;
35+
return combineReducers<Store.ApplicationState>(Object.assign({}, allReducers, { routing: routerReducer }));
3436
}

templates/ReactReduxSpa/ClientApp/dist/_placeholder.txt

-9
This file was deleted.

templates/ReactReduxSpa/ClientApp/routes.tsx

-6
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,3 @@ export default <Route component={ Layout }>
1212
<Route path="(:startDateIndex)" /> { /* Optional route segment that does not affect NavMenu highlighting */ }
1313
</Route>
1414
</Route>;
15-
16-
// Allow Hot Module Reloading
17-
declare var module: any;
18-
if (module.hot) {
19-
module.hot.accept();
20-
}

templates/ReactReduxSpa/Controllers/SampleDataController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public int TemperatureF
3636
{
3737
get
3838
{
39-
return 32 + (int)(TemperatureC / 0.5556);
39+
return 32 + (int)(this.TemperatureC / 0.5556);
4040
}
4141
}
4242
}

templates/ReactReduxSpa/README.md

+24-23
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1-
# Welcome to ASP.NET Core
1+
# Welcome to ASP.NET 5
22

33
We've made some big updates in this release, so it’s **important** that you spend a few minutes to learn what’s new.
44

5-
You've created a new ASP.NET Core project. [Learn what's new](https://go.microsoft.com/fwlink/?LinkId=518016)
5+
You've created a new ASP.NET 5 project. [Learn what's new](http://go.microsoft.com/fwlink/?LinkId=518016)
66

77
## This application consists of:
88

9-
* Sample pages using ASP.NET Core MVC
10-
* [Gulp](https://go.microsoft.com/fwlink/?LinkId=518007) and [Bower](https://go.microsoft.com/fwlink/?LinkId=518004) for managing client-side libraries
11-
* Theming using [Bootstrap](https://go.microsoft.com/fwlink/?LinkID=398939)
9+
* Sample pages using ASP.NET MVC 6
10+
* [Gulp](http://go.microsoft.com/fwlink/?LinkId=518007) and [Bower](http://go.microsoft.com/fwlink/?LinkId=518004) for managing client-side libraries
11+
* Theming using [Bootstrap](http://go.microsoft.com/fwlink/?LinkID=398939)
1212

1313
## How to
1414

15-
* [Add a Controller and View](https://go.microsoft.com/fwlink/?LinkID=398600)
16-
* [Add an appsetting in config and access it in app.](https://go.microsoft.com/fwlink/?LinkID=699562)
17-
* [Manage User Secrets using Secret Manager.](https://go.microsoft.com/fwlink/?LinkId=699315)
18-
* [Use logging to log a message.](https://go.microsoft.com/fwlink/?LinkId=699316)
19-
* [Add packages using NuGet.](https://go.microsoft.com/fwlink/?LinkId=699317)
20-
* [Add client packages using Bower.](https://go.microsoft.com/fwlink/?LinkId=699318)
21-
* [Target development, staging or production environment.](https://go.microsoft.com/fwlink/?LinkId=699319)
15+
* [Add a Controller and View](http://go.microsoft.com/fwlink/?LinkID=398600)
16+
* [Add an appsetting in config and access it in app.](http://go.microsoft.com/fwlink/?LinkID=699562)
17+
* [Manage User Secrets using Secret Manager.](http://go.microsoft.com/fwlink/?LinkId=699315)
18+
* [Use logging to log a message.](http://go.microsoft.com/fwlink/?LinkId=699316)
19+
* [Add packages using NuGet.](http://go.microsoft.com/fwlink/?LinkId=699317)
20+
* [Add client packages using Bower.](http://go.microsoft.com/fwlink/?LinkId=699318)
21+
* [Target development, staging or production environment.](http://go.microsoft.com/fwlink/?LinkId=699319)
2222

2323
## Overview
2424

25-
* [Conceptual overview of what is ASP.NET Core](https://go.microsoft.com/fwlink/?LinkId=518008)
26-
* [Fundamentals of ASP.NET Core such as Startup and middleware.](https://go.microsoft.com/fwlink/?LinkId=699320)
27-
* [Working with Data](https://go.microsoft.com/fwlink/?LinkId=398602)
28-
* [Security](https://go.microsoft.com/fwlink/?LinkId=398603)
29-
* [Client side development](https://go.microsoft.com/fwlink/?LinkID=699321)
30-
* [Develop on different platforms](https://go.microsoft.com/fwlink/?LinkID=699322)
31-
* [Read more on the documentation site](https://go.microsoft.com/fwlink/?LinkID=699323)
25+
* [Conceptual overview of what is ASP.NET 5](http://go.microsoft.com/fwlink/?LinkId=518008)
26+
* [Fundamentals of ASP.NET 5 such as Startup and middleware.](http://go.microsoft.com/fwlink/?LinkId=699320)
27+
* [Working with Data](http://go.microsoft.com/fwlink/?LinkId=398602)
28+
* [Security](http://go.microsoft.com/fwlink/?LinkId=398603)
29+
* [Client side development](http://go.microsoft.com/fwlink/?LinkID=699321)
30+
* [Develop on different platforms](http://go.microsoft.com/fwlink/?LinkID=699322)
31+
* [Read more on the documentation site](http://go.microsoft.com/fwlink/?LinkID=699323)
3232

3333
## Run & Deploy
3434

35-
* [Run your app](https://go.microsoft.com/fwlink/?LinkID=517851)
36-
* [Run tools such as EF migrations and more](https://go.microsoft.com/fwlink/?LinkID=517853)
37-
* [Publish to Microsoft Azure Web Apps](https://go.microsoft.com/fwlink/?LinkID=398609)
35+
* [Run your app](http://go.microsoft.com/fwlink/?LinkID=517851)
36+
* [Run your app on .NET Core](http://go.microsoft.com/fwlink/?LinkID=517852)
37+
* [Run commands in your project.json](http://go.microsoft.com/fwlink/?LinkID=517853)
38+
* [Publish to Microsoft Azure Web Apps](http://go.microsoft.com/fwlink/?LinkID=398609)
3839

39-
We would love to hear your [feedback](https://go.microsoft.com/fwlink/?LinkId=518015)
40+
We would love to hear your [feedback](http://go.microsoft.com/fwlink/?LinkId=518015)

templates/ReactReduxSpa/Views/Home/Index.cshtml

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
ViewData["Title"] = "Home Page";
33
}
44

5-
<div id="react-app" asp-prerender-module="ClientApp/dist/main-server">Loading...</div>
5+
<div id="react-app" asp-prerender-module="ClientApp/boot-server"
6+
asp-prerender-webpack-config="webpack.config.js">Loading...</div>
67

78
@section scripts {
8-
<script src="~/dist/main-client.js" asp-append-version="true"></script>
9+
<script src="~/dist/main.js" asp-append-version="true"></script>
910
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/redux-typed/StrongActions.d.ts: change `Dispatch` at line 16 to `Dispatch<TState>` [aspnet/JavaScriptServices #256](https://github.com/aspnet/JavaScriptServices/pull/256)

templates/ReactReduxSpa/package.json

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
{
2-
"name": "WebApplicationBasic",
2+
"name": "react-redux-spa",
33
"version": "0.0.0",
44
"dependencies": {
5+
"@types/react": "^0.14.29",
6+
"@types/react-dom": "^0.14.14",
7+
"@types/react-redux": "^4.4.29",
8+
"@types/react-router": "^2.0.30",
9+
"@types/react-router-redux": "^4.0.30",
10+
"@types/redux": "^3.5.27",
11+
"@types/redux-thunk": "^2.1.28",
12+
"@types/source-map": "^0.1.26",
13+
"@types/uglify-js": "^2.0.27",
14+
"@types/webpack": "^1.12.31",
15+
"@types/whatwg-fetch": "0.0.28",
516
"aspnet-prerendering": "^1.0.2",
617
"aspnet-webpack": "^1.0.6",
718
"aspnet-webpack-react": "^1.0.2",
@@ -12,6 +23,7 @@
1223
"bootstrap": "^3.3.6",
1324
"css-loader": "^0.23.1",
1425
"domain-task": "^2.0.0",
26+
"extendify": "^1.0.0",
1527
"extract-text-webpack-plugin": "^1.0.1",
1628
"file-loader": "^0.8.5",
1729
"jquery": "^2.2.1",
@@ -25,11 +37,10 @@
2537
"redux-typed": "^1.0.0",
2638
"style-loader": "^0.13.0",
2739
"ts-loader": "^0.8.1",
28-
"typescript": "^1.8.2",
40+
"typescript": "^2.0.0",
2941
"url-loader": "^0.5.7",
30-
"webpack": "^1.12.14",
3142
"webpack-externals-plugin": "^1.0.0",
32-
"webpack-hot-middleware": "^2.10.0",
33-
"webpack-merge": "^0.14.1"
43+
"webpack": "^1.12.14",
44+
"webpack-hot-middleware": "^2.10.0"
3445
}
3546
}

templates/ReactReduxSpa/project.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,25 @@
5151

5252
"publishOptions": {
5353
"include": [
54+
".babelrc",
5455
"appsettings.json",
55-
"ClientApp/dist",
56+
"ClientApp",
5657
"node_modules",
58+
"typings",
5759
"Views",
60+
"tsconfig.json",
61+
"tsd.json",
5862
"web.config",
63+
"webpack.*.js",
5964
"wwwroot"
6065
]
6166
},
6267

6368
"scripts": {
6469
"prepublish": [
6570
"npm install",
66-
"node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod",
67-
"node node_modules/webpack/bin/webpack.js --env.prod"
71+
"node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js",
72+
"node node_modules/webpack/bin/webpack.js"
6873
],
6974
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
7075
},

templates/ReactReduxSpa/template_gitignore

+1-7
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,7 @@ Obj/
2828

2929
# Visual Studio 2015 cache/options directory
3030
.vs/
31-
/wwwroot/dist/**
32-
/ClientApp/dist/**
33-
34-
# Workaround for https://github.com/aspnet/JavaScriptServices/issues/235
35-
!/wwwroot/dist/_placeholder.txt
36-
!/ClientApp/dist/_placeholder.txt
37-
31+
/wwwroot/dist/
3832

3933
# MSTest test Results
4034
[Tt]est[Rr]esult*/

templates/ReactReduxSpa/tsconfig.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55
"jsx": "preserve",
66
"experimentalDecorators": true,
77
"sourceMap": true,
8-
"skipDefaultLibCheck": true
8+
"skipDefaultLibCheck": true,
9+
"lib": ["es6", "dom"],
10+
"typeRoots": [ "node_modules/@types" ],
11+
"types": [ "react", "react-dom", "react-redux", "react-router", "react-router-redux", "redux", "redux-thunk",
12+
"source-map", "uglify-js", "webpack", "webpack/webpack-env", "whatwg-fetch" ]
913
},
14+
"compileOnSave": false,
15+
"buildOnSave": false,
1016
"exclude": [
1117
"bin",
1218
"node_modules"

templates/ReactReduxSpa/tsd.json

-45
This file was deleted.

templates/ReactReduxSpa/typings/react-redux/react-redux.d.ts

-68
This file was deleted.

0 commit comments

Comments
 (0)