Skip to content

Commit ce29248

Browse files
committed
Upgrade to latest React version, and fix sample. Closes #323
1 parent 8b2f242 commit ce29248

File tree

12 files changed

+48
-38
lines changed

12 files changed

+48
-38
lines changed

site/jekyll/getting-started/tutorial.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ Replace the contents of the new view file with the following:
7070
</head>
7171
<body>
7272
<div id="content"></div>
73-
<script src="https://fb.me/react-15.0.1.js"></script>
74-
<script src="https://fb.me/react-dom-15.0.1.js"></script>
73+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
74+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
7575
<script src="@Url.Content("~/Scripts/Tutorial.jsx")"></script>
7676
</body>
7777
</html>
@@ -240,8 +240,8 @@ Markdown is a simple way to format your text inline. For example, surrounding te
240240
First, add the third-party **Showdown** library to your application. This is a JavaScript library which takes Markdown text and converts it to raw HTML. We will add it via NuGet (search for "Showdown" and install it, similar to how you installed ReactJS.NET earlier) and reference the script tag in your view:
241241

242242
```html{3}
243-
<script src="https://fb.me/react-15.0.1.js"></script>
244-
<script src="https://fb.me/react-dom-15.0.1.js"></script>
243+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
244+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
245245
<script src="@Url.Content("~/Scripts/showdown.min.js")"></script>
246246
<script src="@Url.Content("~/Scripts/Tutorial.jsx")"></script>
247247
```
@@ -857,8 +857,8 @@ Now that the bundle has been registered, we need to reference it from the view:
857857
</head>
858858
<body>
859859
<div id="content"></div>
860-
<script src="https://fb.me/react-15.0.1.js"></script>
861-
<script src="https://fb.me/react-dom-15.0.1.js"></script>
860+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
861+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
862862
@Scripts.Render("~/bundles/main")
863863
@Html.ReactInitJavaScript()
864864
</body>
@@ -944,8 +944,8 @@ In the view, we will accept the list of comments as the model, and use `Html.Rea
944944
submitUrl = Url.Action("AddComment"),
945945
pollInterval = 2000,
946946
})
947-
<script src="https://fb.me/react-15.0.1.js"></script>
948-
<script src="https://fb.me/react-dom-15.0.1.js"></script>
947+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
948+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
949949
<script src="@Url.Content("~/Scripts/showdown.min.js")"></script>
950950
<script src="@Url.Content("~/Scripts/Tutorial.jsx")"></script>
951951
@Html.ReactInitJavaScript()

site/jekyll/guides/cassette.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ render from your view using Cassette:
3636
</head>
3737
<body>
3838
...
39-
<script src="https://fb.me/react-15.0.1.js"></script>
40-
<script src="https://fb.me/react-dom-15.0.1.js"></script>
39+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
40+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
4141
@Bundles.RenderScripts()
4242
</body>
4343
```

site/jekyll/guides/server-side-rendering.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ code.
4747
```html
4848
<!-- Load all your scripts normally before calling ReactInitJavaScript -->
4949
<!-- Assumes minification/combination is configured as per previous section -->
50-
<script src="https://fb.me/react-15.0.1.js"></script>
51-
<script src="https://fb.me/react-dom-15.0.1.js"></script>
50+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
51+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
5252
@Scripts.Render("~/bundles/main")
5353
@Html.ReactInitJavaScript()
5454
```
@@ -63,8 +63,8 @@ code.
6363
</div>
6464
</div>
6565

66-
<script src="https://fb.me/react-15.0.1.js"></script>
67-
<script src="https://fb.me/react-dom-15.0.1.js"></script>
66+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
67+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
6868
<script src="/Scripts/HelloWorld.js"></script>
6969
<script>ReactDOM.render(HelloWorld({"name":"Daniel"}), document.getElementById("react1"));</script>
7070
```

site/jekyll/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ bundles.Add(new JsxBundle("~/bundles/main").Include(
112112
})
113113

114114
<!-- Initialise the component in JavaScript too -->
115-
<script src="https://fb.me/react-15.0.1.js"></script>
116-
<script src="https://fb.me/react-dom-15.0.1.js"></script>
115+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
116+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
117117
@Scripts.Render("~/bundles/main")
118118
@Html.ReactInitJavaScript()
119119
```

src/React.Core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"gulp": "~3.9.1",
1212
"gulp-uglify": "~1.5.3",
1313
"json-loader": "~0.5.4",
14-
"react": "~15.1.0",
14+
"react": "~15.3.2",
1515
"vinyl-named": "~1.1.0",
1616
"webpack": "~1.13.1",
1717
"webpack-stream": "~3.2.0"

src/React.Sample.Cassette/Views/Home/Index.cshtml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
@Html.React("CommentsBox", new { initialComments = Model.Comments })
2121

2222
<!-- Load all required scripts (React + the site's scripts) -->
23-
<script src="https://fb.me/react-15.0.1.js"></script>
24-
<script src="https://fb.me/react-dom-15.0.1.js"></script>
23+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
24+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
2525
@Bundles.RenderScripts()
2626
<!-- Render the code to initialise the component -->
2727
@Html.ReactInitJavaScript()

src/React.Sample.Mvc4/Views/Home/Index.cshtml

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
@Html.React("CommentsBox", new { initialComments = Model.Comments, page = Model.Page })
1818

1919
<!-- Load all required scripts (React + the site's scripts) -->
20-
<script src="https://fb.me/react-15.0.1.js"></script>
21-
<script src="https://fb.me/react-dom-15.0.1.js"></script>
20+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
21+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
2222
@Scripts.Render("~/bundles/main")
2323
<!-- Render the code to initialise the component -->
2424
@Html.ReactInitJavaScript()
2525
</body>
26-
</html>
26+
</html>

src/React.Sample.Mvc6/Controllers/HomeController.cs

+10-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
using System.Collections.Generic;
1414
using System.Linq;
1515
using Microsoft.AspNetCore.Mvc;
16+
using Newtonsoft.Json;
17+
using Newtonsoft.Json.Serialization;
1618
using React.Sample.Mvc6.Models;
1719
using React.Sample.Mvc6.ViewModels;
1820

@@ -26,6 +28,7 @@ public class AuthorModel
2628
public class CommentModel
2729
{
2830
public AuthorModel Author { get; set; }
31+
public int Id { get; set; }
2932
public string Text { get; set; }
3033
}
3134
}
@@ -62,13 +65,13 @@ public HomeController()
6265
};
6366
_comments = new List<CommentModel>
6467
{
65-
new CommentModel { Author = _authors["daniel"], Text = "First!!!!111!" },
66-
new CommentModel { Author = _authors["zpao"], Text = "React is awesome!" },
67-
new CommentModel { Author = _authors["cpojer"], Text = "Awesome!" },
68-
new CommentModel { Author = _authors["vjeux"], Text = "Hello World" },
69-
new CommentModel { Author = _authors["daniel"], Text = "Foo" },
70-
new CommentModel { Author = _authors["daniel"], Text = "Bar" },
71-
new CommentModel { Author = _authors["daniel"], Text = "FooBarBaz" },
68+
new CommentModel { Id = 1, Author = _authors["daniel"], Text = "First!!!!111!" },
69+
new CommentModel { Id = 2, Author = _authors["zpao"], Text = "React is awesome!" },
70+
new CommentModel { Id = 3, Author = _authors["cpojer"], Text = "Awesome!" },
71+
new CommentModel { Id = 4, Author = _authors["vjeux"], Text = "Hello World" },
72+
new CommentModel { Id = 5, Author = _authors["daniel"], Text = "Foo" },
73+
new CommentModel { Id = 6, Author = _authors["daniel"], Text = "Bar" },
74+
new CommentModel { Id = 7, Author = _authors["daniel"], Text = "FooBarBaz" },
7275
};
7376
}
7477

src/React.Sample.Mvc6/Startup.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
using Microsoft.Extensions.Configuration;
1414
using Microsoft.Extensions.DependencyInjection;
1515
using Microsoft.Extensions.Logging;
16+
using Newtonsoft.Json;
17+
using Newtonsoft.Json.Serialization;
1618
using React.AspNet;
1719

1820
namespace React.Sample.Mvc6
@@ -65,7 +67,12 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
6567
{
6668
config
6769
.SetReuseJavaScriptEngines(true)
68-
.AddScript("~/js/Sample.jsx");
70+
.AddScript("~/js/Sample.jsx")
71+
.SetJsonSerializerSettings(new JsonSerializerSettings
72+
{
73+
ContractResolver = new CamelCasePropertyNamesContractResolver(),
74+
StringEscapeHandling = StringEscapeHandling.EscapeHtml,
75+
});
6976
});
7077

7178
// Add static files to the request pipeline.

src/React.Sample.Mvc6/Views/Home/Index.cshtml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
@Html.React("CommentsBox", new { initialComments = Model.Comments })
1818

1919
<!-- Load all required scripts (React + the site's scripts) -->
20-
<script src="https://fb.me/react-15.0.1.js"></script>
21-
<script src="https://fb.me/react-dom-15.0.1.js"></script>
20+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
21+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
2222
<script src="~/js/Sample.jsx"></script>
2323
<!-- Render the code to initialise the component -->
2424
@Html.ReactInitJavaScript()

src/React.Sample.Mvc6/wwwroot/js/Sample.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var CommentsBox = React.createClass({
4242
},
4343
render() {
4444
var commentNodes = this.state.comments.map(comment =>
45-
<Comment author={comment.Author}>{comment.Text}</Comment>
45+
<Comment key={comment.id} author={comment.author}>{comment.text}</Comment>
4646
);
4747

4848
return (
@@ -78,7 +78,7 @@ var Comment = React.createClass({
7878
return (
7979
<li>
8080
<Avatar author={this.props.author} />
81-
<strong>{this.props.author.Name}</strong>{': '}
81+
<strong>{this.props.author.name}</strong>{': '}
8282
{this.props.children}
8383
</li>
8484
);
@@ -93,14 +93,14 @@ var Avatar = React.createClass({
9393
return (
9494
<img
9595
src={this.getPhotoUrl(this.props.author)}
96-
alt={'Photo of ' + this.props.author.Name}
96+
alt={'Photo of ' + this.props.author.name}
9797
width={50}
9898
height={50}
9999
className="commentPhoto"
100100
/>
101101
);
102102
},
103103
getPhotoUrl(author) {
104-
return 'https://avatars.githubusercontent.com/' + author.GithubUsername + '?s=50';
104+
return 'https://avatars.githubusercontent.com/' + author.githubUsername + '?s=50';
105105
}
106106
});

src/React.Sample.Webpack/Views/Home/Index.cshtml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
@Html.React("Components.CommentsBox", new { initialComments = Model.Comments })
1717

1818
<!-- Load all required scripts (React + the site's scripts) -->
19-
<script src="https://fb.me/react-15.0.1.js"></script>
20-
<script src="https://fb.me/react-dom-15.0.1.js"></script>
19+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
20+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
2121
<script src="@Url.Content("~/build/client.bundle.js")"></script>
2222
<!-- Render the code to initialise the component -->
2323
@Html.ReactInitJavaScript()

0 commit comments

Comments
 (0)