From 0bd9e36a8ba8951c6496ca9f5e1f89c0a5687e08 Mon Sep 17 00:00:00 2001 From: Dustin Masters Date: Sun, 15 Oct 2017 21:43:45 -0700 Subject: [PATCH 1/7] Update to React 16 --- src/React.Core/Resources/react.js | 11 ++-- src/React.Core/package.json | 4 +- src/React.Sample.Mvc6/wwwroot/js/Sample.jsx | 60 +++++++++++---------- 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/src/React.Core/Resources/react.js b/src/React.Core/Resources/react.js index 2fecd563f..0e69b3983 100644 --- a/src/React.Core/Resources/react.js +++ b/src/React.Core/Resources/react.js @@ -3,13 +3,14 @@ * All rights reserved. * * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant + * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ // Exports all the parts of React that ReactJS.NET cares about. module.exports = { - React: require('react/lib/ReactWithAddons'), - ReactDOM: require('react/lib/ReactDOM'), - ReactDOMServer: require('react/lib/ReactDOMServer') -}; \ No newline at end of file + React: require('react'), + ReactDOM: require('react-dom'), + ReactDOMServer: require('react-dom/server'), + PropTypes: require('prop-types'), +}; diff --git a/src/React.Core/package.json b/src/React.Core/package.json index bc0607b8b..29dd13368 100644 --- a/src/React.Core/package.json +++ b/src/React.Core/package.json @@ -11,7 +11,9 @@ "gulp": "~3.9.1", "gulp-uglify": "~1.5.3", "json-loader": "~0.5.4", - "react": "~15.3.2", + "prop-types": "~15.6.0", + "react": "~16.0.0", + "react-dom": "~16.0.0", "vinyl-named": "~1.1.0", "webpack": "~1.13.1", "webpack-stream": "~3.2.0" diff --git a/src/React.Sample.Mvc6/wwwroot/js/Sample.jsx b/src/React.Sample.Mvc6/wwwroot/js/Sample.jsx index 90cbfc15c..80aaedbe3 100644 --- a/src/React.Sample.Mvc6/wwwroot/js/Sample.jsx +++ b/src/React.Sample.Mvc6/wwwroot/js/Sample.jsx @@ -3,23 +3,23 @@ * All rights reserved. * * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant + * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ -var CommentsBox = React.createClass({ - propTypes: { - initialComments: React.PropTypes.array.isRequired - }, - getInitialState() { - return { - comments: this.props.initialComments, - page: 1, - hasMore: true, - loadingMore: false - }; - }, - loadMoreClicked(evt) { +class CommentsBox extends React.Component { + static propTypes = { + initialComments: PropTypes.array.isRequired + }; + + state = { + comments: this.props.initialComments, + page: 1, + hasMore: true, + loadingMore: false + }; + + loadMoreClicked = (evt) => { var nextPage = this.state.page + 1; this.setState({ page: nextPage, @@ -39,7 +39,8 @@ var CommentsBox = React.createClass({ }; xhr.send(); evt.preventDefault(); - }, + } + render() { var commentNodes = this.state.comments.map(comment => {comment.text} @@ -54,7 +55,8 @@ var CommentsBox = React.createClass({ {this.renderMoreLink()} ); - }, + } + renderMoreLink() { if (this.state.loadingMore) { return Loading...; @@ -68,12 +70,13 @@ var CommentsBox = React.createClass({ return No more comments; } } -}); +} + +class Comment extends React.Component { + static propTypes = { + author: PropTypes.object.isRequired + } -var Comment = React.createClass({ - propTypes: { - author: React.PropTypes.object.isRequired - }, render() { return (
  • @@ -83,12 +86,13 @@ var Comment = React.createClass({
  • ); } -}); +} + +class Avatar extends React.Component { + static propTypes = { + author: PropTypes.object.isRequired + } -var Avatar = React.createClass({ - propTypes: { - author: React.PropTypes.object.isRequired - }, render() { return ( ); - }, + } getPhotoUrl(author) { return 'https://avatars.githubusercontent.com/' + author.githubUsername + '?s=50'; } -}); +} From 1589e5af3882b90e00022c2167eb27e91ec78c9f Mon Sep 17 00:00:00 2001 From: Dustin Masters Date: Thu, 26 Oct 2017 22:00:46 -0700 Subject: [PATCH 2/7] Use hydrate instead of render --- src/React.Core/ReactComponent.cs | 2 +- src/React.Router/ReactRouterComponent.cs | 2 +- tests/React.Tests/Core/ReactComponentTest.cs | 2 +- tests/React.Tests/Router/ReactRouterComponentTest.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/React.Core/ReactComponent.cs b/src/React.Core/ReactComponent.cs index 140a1bb5b..43c40628c 100644 --- a/src/React.Core/ReactComponent.cs +++ b/src/React.Core/ReactComponent.cs @@ -164,7 +164,7 @@ public virtual string RenderHtml(bool renderContainerOnly = false, bool renderSe public virtual string RenderJavaScript() { return string.Format( - "ReactDOM.render({0}, document.getElementById({1}))", + "ReactDOM.hydrate({0}, document.getElementById({1}))", GetComponentInitialiser(), JsonConvert.SerializeObject(ContainerId, _configuration.JsonSerializerSettings) // SerializeObject accepts null settings ); diff --git a/src/React.Router/ReactRouterComponent.cs b/src/React.Router/ReactRouterComponent.cs index c2d553027..1d90b00ab 100644 --- a/src/React.Router/ReactRouterComponent.cs +++ b/src/React.Router/ReactRouterComponent.cs @@ -89,7 +89,7 @@ protected override string GetComponentInitialiser() public override string RenderJavaScript() { return string.Format( - "ReactDOM.render({0}, document.getElementById({1}))", + "ReactDOM.hydrate({0}, document.getElementById({1}))", base.GetComponentInitialiser(), JsonConvert.SerializeObject(ContainerId, _configuration.JsonSerializerSettings) // SerializeObject accepts null settings ); diff --git a/tests/React.Tests/Core/ReactComponentTest.cs b/tests/React.Tests/Core/ReactComponentTest.cs index 0a3d20707..8585345cf 100644 --- a/tests/React.Tests/Core/ReactComponentTest.cs +++ b/tests/React.Tests/Core/ReactComponentTest.cs @@ -155,7 +155,7 @@ public void RenderJavaScriptShouldCallRenderComponent() var result = component.RenderJavaScript(); Assert.Equal( - @"ReactDOM.render(React.createElement(Foo, {""hello"":""World""}), document.getElementById(""container""))", + @"ReactDOM.hydrate(React.createElement(Foo, {""hello"":""World""}), document.getElementById(""container""))", result ); } diff --git a/tests/React.Tests/Router/ReactRouterComponentTest.cs b/tests/React.Tests/Router/ReactRouterComponentTest.cs index 59b90b06a..731b26341 100644 --- a/tests/React.Tests/Router/ReactRouterComponentTest.cs +++ b/tests/React.Tests/Router/ReactRouterComponentTest.cs @@ -30,7 +30,7 @@ public void RenderJavaScriptShouldNotIncludeContextOrPath() var result = component.RenderJavaScript(); Assert.Equal( - @"ReactDOM.render(React.createElement(Foo, {""hello"":""World""}), document.getElementById(""container""))", + @"ReactDOM.hydrate(React.createElement(Foo, {""hello"":""World""}), document.getElementById(""container""))", result ); } From 37bc95b3d54f7ae8e091758a175a4201bed77d2a Mon Sep 17 00:00:00 2001 From: Dustin Masters Date: Thu, 26 Oct 2017 22:01:05 -0700 Subject: [PATCH 3/7] Update mvc4 sample --- src/React.Sample.Mvc4/Content/Sample.jsx | 58 +++++++++++-------- src/React.Sample.Mvc4/Views/Home/Index.cshtml | 11 ++-- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/React.Sample.Mvc4/Content/Sample.jsx b/src/React.Sample.Mvc4/Content/Sample.jsx index f7886ce9a..36f74ebca 100644 --- a/src/React.Sample.Mvc4/Content/Sample.jsx +++ b/src/React.Sample.Mvc4/Content/Sample.jsx @@ -3,23 +3,23 @@ * All rights reserved. * * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant + * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ -var CommentsBox = React.createClass({ - propTypes: { - initialComments: React.PropTypes.array.isRequired, - page: React.PropTypes.number - }, - getInitialState() { - return { +class CommentsBox extends React.Component { + constructor(props) { + super(props); + + this.state = { comments: this.props.initialComments, page: this.props.page, hasMore: true, loadingMore: false - }; - }, + } + } + + loadMoreClicked(evt) { var nextPage = this.state.page + 1; this.setState({ @@ -41,7 +41,8 @@ var CommentsBox = React.createClass({ }; xhr.send(); evt.preventDefault(); - }, + } + render() { var commentNodes = this.state.comments.map(comment => {comment.Text} @@ -56,13 +57,14 @@ var CommentsBox = React.createClass({ {this.renderMoreLink()} ); - }, + } + renderMoreLink() { if (this.state.loadingMore) { return Loading...; } else if (this.state.hasMore) { return ( - + Load More ); @@ -70,12 +72,14 @@ var CommentsBox = React.createClass({ return No more comments; } } -}); +} -var Comment = React.createClass({ - propTypes: { - author: React.PropTypes.object.isRequired - }, +CommentsBox.propTypes = { + initialComments: PropTypes.array.isRequired, + page: PropTypes.number +} + +class Comment extends React.Component { render() { return (
  • @@ -85,12 +89,12 @@ var Comment = React.createClass({
  • ); } -}); +} +Comment.propTypes = { + author: PropTypes.object.isRequired +}; -var Avatar = React.createClass({ - propTypes: { - author: React.PropTypes.object.isRequired - }, +class Avatar extends React.Component { render() { return ( ); - }, + } + getPhotoUrl(author) { return 'https://avatars.githubusercontent.com/' + author.GithubUsername + '?s=50'; } -}); +} +Avatar.propTypes = { + author: PropTypes.object.isRequired +}; diff --git a/src/React.Sample.Mvc4/Views/Home/Index.cshtml b/src/React.Sample.Mvc4/Views/Home/Index.cshtml index 6f15eda80..70eb54233 100644 --- a/src/React.Sample.Mvc4/Views/Home/Index.cshtml +++ b/src/React.Sample.Mvc4/Views/Home/Index.cshtml @@ -8,17 +8,18 @@

    - This is an example of ReactJS.NET's server-side rendering. The initial state of this + This is an example of ReactJS.NET's server-side rendering. The initial state of this comments box is rendered server-side, and additional data is loaded via AJAX and rendered client-side.

    - + @Html.React("CommentsBox", new { initialComments = Model.Comments, page = Model.Page }) - + - - + + + @Scripts.Render("~/bundles/main") @Html.ReactInitJavaScript() From 4162ecaa6473fc080c5e308a5f0deeb48c3d018f Mon Sep 17 00:00:00 2001 From: Dustin Masters Date: Thu, 26 Oct 2017 22:36:12 -0700 Subject: [PATCH 4/7] Update samples --- src/React.Sample.Cassette/Content/Sample.jsx | 78 ++++++++++--------- src/React.Sample.ConsoleApp/Sample.jsx | 6 +- src/React.Sample.Mvc4/Content/Sample.jsx | 45 +++++------ src/React.Sample.Owin/Content/Sample.jsx | 76 +++++++++--------- .../Content/components/Avatar.jsx | 22 +++--- .../Content/components/Comment.jsx | 15 ++-- .../Content/components/CommentsBox.jsx | 34 ++++---- 7 files changed, 145 insertions(+), 131 deletions(-) diff --git a/src/React.Sample.Cassette/Content/Sample.jsx b/src/React.Sample.Cassette/Content/Sample.jsx index 35d9104e6..ffaa668eb 100644 --- a/src/React.Sample.Cassette/Content/Sample.jsx +++ b/src/React.Sample.Cassette/Content/Sample.jsx @@ -3,24 +3,25 @@ * All rights reserved. * * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant + * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ -var CommentsBox = React.createClass({ - propTypes: { - initialComments: React.PropTypes.array.isRequired, - commentsPerPage: React.PropTypes.number.isRequired - }, - getInitialState: function() { - return { - comments: this.props.initialComments, - page: 1, - hasMore: true, - loadingMore: false - }; - }, - loadMoreClicked: function(evt) { + +class CommentsBox extends React.Component { + static propTypes = { + initialComments: PropTypes.array.isRequired, + commentsPerPage: PropTypes.number.isRequired + }; + + state = { + comments: this.props.initialComments, + page: 1, + hasMore: true, + loadingMore: false + }; + + loadMoreClicked = (evt) => { var nextPage = this.state.page + 1; this.setState({ page: nextPage, @@ -40,8 +41,9 @@ var CommentsBox = React.createClass({ }.bind(this); xhr.send(); evt.preventDefault(); - }, - render: function() { + }; + + render() { var commentNodes = this.state.comments.map(function (comment) { return {comment.Text}; }); @@ -55,8 +57,9 @@ var CommentsBox = React.createClass({ {this.renderMoreLink()} ); - }, - renderMoreLink: function() { + } + + renderMoreLink = () => { if (this.state.loadingMore) { return Loading...; } else if (this.state.hasMore) { @@ -68,14 +71,15 @@ var CommentsBox = React.createClass({ } else { return No more comments; } - } -}); + }; +} + +class Comment extends React.Component { + static propTypes = { + author: PropTypes.object.isRequired + }; -var Comment = React.createClass({ - propTypes: { - author: React.PropTypes.object.isRequired - }, - render: function() { + render() { return (
  • @@ -84,13 +88,14 @@ var Comment = React.createClass({
  • ); } -}); +} + +class Avatar extends React.Component { + static propTypes = { + author: PropTypes.object.isRequired + }; -var Avatar = React.createClass({ - propTypes: { - author: React.PropTypes.object.isRequired - }, - render: function() { + render() { return ( ); - }, - getPhotoUrl: function(author) { - return 'https://avatars.githubusercontent.com/' + author.GithubUsername + '?s=50'; } -}); + + getPhotoUrl = (author) => { + return 'https://avatars.githubusercontent.com/' + author.GithubUsername + '?s=50'; + }; +} diff --git a/src/React.Sample.ConsoleApp/Sample.jsx b/src/React.Sample.ConsoleApp/Sample.jsx index 18a448d7a..e8e23fceb 100644 --- a/src/React.Sample.ConsoleApp/Sample.jsx +++ b/src/React.Sample.ConsoleApp/Sample.jsx @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2015, Facebook, Inc. * All rights reserved. * @@ -7,7 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -var HelloWorld = React.createClass({ +class HelloWorld extends React.Component { render() { return (
    @@ -15,4 +15,4 @@ var HelloWorld = React.createClass({
    ); } -}); \ No newline at end of file +} diff --git a/src/React.Sample.Mvc4/Content/Sample.jsx b/src/React.Sample.Mvc4/Content/Sample.jsx index 36f74ebca..8875ef8f1 100644 --- a/src/React.Sample.Mvc4/Content/Sample.jsx +++ b/src/React.Sample.Mvc4/Content/Sample.jsx @@ -8,19 +8,19 @@ */ class CommentsBox extends React.Component { - constructor(props) { - super(props); + static propTypes = { + initialComments: React.PropTypes.array.isRequired, + page: React.PropTypes.number + }; - this.state = { + state = { comments: this.props.initialComments, page: this.props.page, hasMore: true, loadingMore: false - } - } - + }; - loadMoreClicked(evt) { + loadMoreClicked = (evt) => { var nextPage = this.state.page + 1; this.setState({ page: nextPage, @@ -41,7 +41,7 @@ class CommentsBox extends React.Component { }; xhr.send(); evt.preventDefault(); - } + }; render() { var commentNodes = this.state.comments.map(comment => @@ -59,27 +59,26 @@ class CommentsBox extends React.Component { ); } - renderMoreLink() { + renderMoreLink = () => { if (this.state.loadingMore) { return Loading...; } else if (this.state.hasMore) { return ( - + Load More ); } else { return No more comments; } - } -} - -CommentsBox.propTypes = { - initialComments: PropTypes.array.isRequired, - page: PropTypes.number + }; } class Comment extends React.Component { + static propTypes = { + author: React.PropTypes.object.isRequired + }; + render() { return (
  • @@ -90,11 +89,12 @@ class Comment extends React.Component { ); } } -Comment.propTypes = { - author: PropTypes.object.isRequired -}; class Avatar extends React.Component { + static propTypes = { + author: React.PropTypes.object.isRequired + }; + render() { return ( { return 'https://avatars.githubusercontent.com/' + author.GithubUsername + '?s=50'; - } + }; } -Avatar.propTypes = { - author: PropTypes.object.isRequired -}; diff --git a/src/React.Sample.Owin/Content/Sample.jsx b/src/React.Sample.Owin/Content/Sample.jsx index a2407b415..fa732d053 100644 --- a/src/React.Sample.Owin/Content/Sample.jsx +++ b/src/React.Sample.Owin/Content/Sample.jsx @@ -3,23 +3,23 @@ * All rights reserved. * * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant + * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ -var CommentsBox = React.createClass({ - propTypes: { - initialComments: React.PropTypes.array.isRequired - }, - getInitialState() { - return { - comments: this.props.initialComments || [], - page: 0, - hasMore: true, - loadingMore: false - }; - }, - loadMoreClicked(evt) { +class CommentsBox extends React.Component { + static propTypes = { + initialComments: PropTypes.array.isRequired + }; + + state = { + comments: this.props.initialComments || [], + page: 0, + hasMore: true, + loadingMore: false + }; + + loadMoreClicked = (evt) => { var nextPage = this.state.page + 1; this.setState({ page: nextPage, @@ -39,10 +39,12 @@ var CommentsBox = React.createClass({ }; xhr.send(); evt.preventDefault(); - }, - componentDidMount: function() { - this.loadMoreClicked({ target: { href: "/comments/page-1" } }); - }, + }; + + componentDidMount() { + this.loadMoreClicked({ target: { href: "/comments/page-1" } }); + } + render() { var commentNodes = this.state.comments.map(comment => {comment.Text} @@ -57,8 +59,9 @@ var CommentsBox = React.createClass({ {this.renderMoreLink()} ); - }, - renderMoreLink() { + } + + renderMoreLink = () => { if (this.state.loadingMore) { return Loading...; } else if (this.state.hasMore) { @@ -70,13 +73,14 @@ var CommentsBox = React.createClass({ } else { return No more comments; } - } -}); + }; +} + +class Comment extends React.Component { + static propTypes = { + author: PropTypes.object.isRequired + }; -var Comment = React.createClass({ - propTypes: { - author: React.PropTypes.object.isRequired - }, render() { return (
  • @@ -86,12 +90,13 @@ var Comment = React.createClass({
  • ); } -}); +} + +class Avatar extends React.Component { + static propTypes = { + author: PropTypes.object.isRequired + }; -var Avatar = React.createClass({ - propTypes: { - author: React.PropTypes.object.isRequired - }, render() { return ( ); - }, - getPhotoUrl(author) { - return 'https://avatars.githubusercontent.com/' + author.GithubUsername + '?s=50'; } -}); + + getPhotoUrl = (author) => { + return 'https://avatars.githubusercontent.com/' + author.GithubUsername + '?s=50'; + }; +} diff --git a/src/React.Sample.Webpack/Content/components/Avatar.jsx b/src/React.Sample.Webpack/Content/components/Avatar.jsx index 97f5b4a26..542dd2f2b 100644 --- a/src/React.Sample.Webpack/Content/components/Avatar.jsx +++ b/src/React.Sample.Webpack/Content/components/Avatar.jsx @@ -3,16 +3,17 @@ * All rights reserved. * * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant + * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ var React = require('react'); -var Avatar = React.createClass({ - propTypes: { - author: React.PropTypes.object.isRequired - }, +class Avatar extends React.Component { + static propTypes = { + author: PropTypes.object.isRequired + }; + render() { return ( ); - }, - getPhotoUrl(author) { - return 'https://avatars.githubusercontent.com/' + author.GithubUsername + '?s=50'; } -}); -module.exports = Avatar; \ No newline at end of file + getPhotoUrl = (author) => { + return 'https://avatars.githubusercontent.com/' + author.GithubUsername + '?s=50'; + }; +} + +module.exports = Avatar; diff --git a/src/React.Sample.Webpack/Content/components/Comment.jsx b/src/React.Sample.Webpack/Content/components/Comment.jsx index 5a79c827a..0b944b9f5 100644 --- a/src/React.Sample.Webpack/Content/components/Comment.jsx +++ b/src/React.Sample.Webpack/Content/components/Comment.jsx @@ -3,17 +3,18 @@ * All rights reserved. * * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant + * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ var Avatar = require('./Avatar'); var React = require('react'); -var Comment = React.createClass({ - propTypes: { - author: React.PropTypes.object.isRequired - }, +class Comment extends React.Component { + static propTypes = { + author: PropTypes.object.isRequired + }; + render() { return (
  • @@ -23,6 +24,6 @@ var Comment = React.createClass({
  • ); } -}); +} -module.exports = Comment; \ No newline at end of file +module.exports = Comment; diff --git a/src/React.Sample.Webpack/Content/components/CommentsBox.jsx b/src/React.Sample.Webpack/Content/components/CommentsBox.jsx index 24272eb54..b022d1043 100644 --- a/src/React.Sample.Webpack/Content/components/CommentsBox.jsx +++ b/src/React.Sample.Webpack/Content/components/CommentsBox.jsx @@ -3,26 +3,26 @@ * All rights reserved. * * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant + * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ var Comment = require('./Comment'); var React = require('react'); -var CommentsBox = React.createClass({ - propTypes: { - initialComments: React.PropTypes.array.isRequired - }, - getInitialState() { - return { +class CommentsBox extends React.Component { + static propTypes = { + initialComments: PropTypes.array.isRequired + }; + + state = { comments: this.props.initialComments, page: 1, hasMore: true, loadingMore: false }; - }, - loadMoreClicked(evt) { + + loadMoreClicked = (evt) => { var nextPage = this.state.page + 1; this.setState({ page: nextPage, @@ -42,8 +42,9 @@ var CommentsBox = React.createClass({ }; xhr.send(); evt.preventDefault(); - }, - render() { + }; + + render() { var commentNodes = this.state.comments.map(comment => {comment.Text} ); @@ -57,8 +58,9 @@ var CommentsBox = React.createClass({ {this.renderMoreLink()} ); - }, - renderMoreLink() { + } + + renderMoreLink = () => { if (this.state.loadingMore) { return Loading...; } else if (this.state.hasMore) { @@ -70,7 +72,7 @@ var CommentsBox = React.createClass({ } else { return No more comments; } - } -}); + }; +} -module.exports = CommentsBox; \ No newline at end of file +module.exports = CommentsBox; From 8e6309b1a17e41e2e5fab79b1863de6bdec1f3f2 Mon Sep 17 00:00:00 2001 From: Dustin Masters Date: Thu, 26 Oct 2017 22:46:02 -0700 Subject: [PATCH 5/7] Update more samples --- src/React.Sample.Cassette/Views/Home/Index.cshtml | 13 +++++++------ src/React.Sample.Mvc6/Views/Home/Index.cshtml | 7 ++++--- src/React.Sample.Owin/Content/Index.html | 9 +++++---- src/React.Sample.Owin/Content/Sample.jsx | 5 ++++- src/React.Sample.Webpack/Views/Home/Index.cshtml | 13 +++++++------ src/React.Sample.Webpack/package.json | 3 ++- tutorial-code/Views/Home/Index.cshtml | 7 ++++--- 7 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/React.Sample.Cassette/Views/Home/Index.cshtml b/src/React.Sample.Cassette/Views/Home/Index.cshtml index 46d143409..5de9a00d4 100644 --- a/src/React.Sample.Cassette/Views/Home/Index.cshtml +++ b/src/React.Sample.Cassette/Views/Home/Index.cshtml @@ -11,19 +11,20 @@

    - This is an example of ReactJS.NET's server-side rendering. The initial state of this + This is an example of ReactJS.NET's server-side rendering. The initial state of this comments box is rendered server-side, and additional data is loaded via AJAX and rendered client-side.

    - + @Html.React("CommentsBox", new { initialComments = Model.Comments }) - + - - + + + @Bundles.RenderScripts() @Html.ReactInitJavaScript() - \ No newline at end of file + diff --git a/src/React.Sample.Mvc6/Views/Home/Index.cshtml b/src/React.Sample.Mvc6/Views/Home/Index.cshtml index dbd26df15..0ac37e5e8 100644 --- a/src/React.Sample.Mvc6/Views/Home/Index.cshtml +++ b/src/React.Sample.Mvc6/Views/Home/Index.cshtml @@ -17,10 +17,11 @@ @Html.React("CommentsBox", new { initialComments = Model.Comments }) - - + + + @Html.ReactInitJavaScript() - \ No newline at end of file + diff --git a/src/React.Sample.Owin/Content/Index.html b/src/React.Sample.Owin/Content/Index.html index f84b1800b..7b42c3bd8 100644 --- a/src/React.Sample.Owin/Content/Index.html +++ b/src/React.Sample.Owin/Content/Index.html @@ -1,4 +1,4 @@ - + @@ -8,8 +8,9 @@
    - - + + + - \ No newline at end of file + diff --git a/src/React.Sample.Owin/Content/Sample.jsx b/src/React.Sample.Owin/Content/Sample.jsx index fa732d053..659164b6d 100644 --- a/src/React.Sample.Owin/Content/Sample.jsx +++ b/src/React.Sample.Owin/Content/Sample.jsx @@ -38,7 +38,10 @@ class CommentsBox extends React.Component { }); }; xhr.send(); - evt.preventDefault(); + + if (evt.preventDefault) { + evt.preventDefault(); + } }; componentDidMount() { diff --git a/src/React.Sample.Webpack/Views/Home/Index.cshtml b/src/React.Sample.Webpack/Views/Home/Index.cshtml index 89ef0c7ee..5a4f389f2 100644 --- a/src/React.Sample.Webpack/Views/Home/Index.cshtml +++ b/src/React.Sample.Webpack/Views/Home/Index.cshtml @@ -7,19 +7,20 @@

    - This is an example of ReactJS.NET's server-side rendering. The initial state of this + This is an example of ReactJS.NET's server-side rendering. The initial state of this comments box is rendered server-side, and additional data is loaded via AJAX and rendered client-side.

    - + @Html.React("Components.CommentsBox", new { initialComments = Model.Comments }) - + - - + + + @Html.ReactInitJavaScript() - \ No newline at end of file + diff --git a/src/React.Sample.Webpack/package.json b/src/React.Sample.Webpack/package.json index e18b171a7..5bc49c1e1 100644 --- a/src/React.Sample.Webpack/package.json +++ b/src/React.Sample.Webpack/package.json @@ -4,7 +4,8 @@ "description": "Webpack + ASP.NET MVC 4 sample for ReactJS.NET", "main": "gulpfile.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "build": "webpack" }, "author": "", "license": "BSD", diff --git a/tutorial-code/Views/Home/Index.cshtml b/tutorial-code/Views/Home/Index.cshtml index 5b2dd62a9..8260b7f9b 100644 --- a/tutorial-code/Views/Home/Index.cshtml +++ b/tutorial-code/Views/Home/Index.cshtml @@ -14,10 +14,11 @@ submitUrl = Url.Action("AddComment"), pollInterval = 2000, }) - - + + + @Html.ReactInitJavaScript() - \ No newline at end of file + From 219b846b0549a73a50a12b0ae21f1d52e257a279 Mon Sep 17 00:00:00 2001 From: Dustin Masters Date: Mon, 30 Oct 2017 18:28:38 -0700 Subject: [PATCH 6/7] Add stage-0 transform to webpack sample --- src/React.Sample.Webpack/.babelrc | 4 +- .../Content/components/CommentsBox.jsx | 1 + src/React.Sample.Webpack/package.json | 39 ++++++++++--------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/React.Sample.Webpack/.babelrc b/src/React.Sample.Webpack/.babelrc index fbbce61e9..a79b8b6fd 100644 --- a/src/React.Sample.Webpack/.babelrc +++ b/src/React.Sample.Webpack/.babelrc @@ -1,3 +1,3 @@ { - "presets": ["es2015", "react"] -} \ No newline at end of file + "presets": ["es2015", "react", "stage-0"] +} diff --git a/src/React.Sample.Webpack/Content/components/CommentsBox.jsx b/src/React.Sample.Webpack/Content/components/CommentsBox.jsx index b022d1043..95c6b30f0 100644 --- a/src/React.Sample.Webpack/Content/components/CommentsBox.jsx +++ b/src/React.Sample.Webpack/Content/components/CommentsBox.jsx @@ -32,6 +32,7 @@ class CommentsBox extends React.Component { var url = evt.target.href; var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); + xhr.setRequestHeader('Content-Type', 'application/json'); xhr.onload = () => { var data = JSON.parse(xhr.responseText); this.setState({ diff --git a/src/React.Sample.Webpack/package.json b/src/React.Sample.Webpack/package.json index 5bc49c1e1..757d44f59 100644 --- a/src/React.Sample.Webpack/package.json +++ b/src/React.Sample.Webpack/package.json @@ -1,20 +1,21 @@ -{ - "name": "React.Sample.Webpack", - "version": "0.0.1", - "description": "Webpack + ASP.NET MVC 4 sample for ReactJS.NET", - "main": "gulpfile.js", - "scripts": { +{ + "name": "React.Sample.Webpack", + "version": "0.0.1", + "description": "Webpack + ASP.NET MVC 4 sample for ReactJS.NET", + "main": "gulpfile.js", + "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "build": "webpack" - }, - "author": "", - "license": "BSD", - "devDependencies": { - "babel-core": "^6.3.17", - "babel-loader": "^6.2.0", - "babel-preset-es2015": "^6.3.13", - "babel-preset-react": "^6.3.13", - "expose-loader": "^0.7.1", - "webpack": "^1.12.9" - } -} + "build": "webpack" + }, + "author": "", + "license": "BSD", + "devDependencies": { + "babel-core": "^6.3.17", + "babel-loader": "^6.2.0", + "babel-preset-es2015": "^6.3.13", + "babel-preset-react": "^6.3.13", + "babel-preset-stage-0": "~6.5.0", + "expose-loader": "^0.7.1", + "webpack": "^1.12.9" + } +} From 3ea897801e208f416cd8f0c1f6ab06c69ff86c02 Mon Sep 17 00:00:00 2001 From: Dustin Masters Date: Mon, 30 Oct 2017 18:30:24 -0700 Subject: [PATCH 7/7] Use LF line endings --- src/React.Sample.Webpack/package.json | 42 +++++++++++++-------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/React.Sample.Webpack/package.json b/src/React.Sample.Webpack/package.json index 757d44f59..87edb9f90 100644 --- a/src/React.Sample.Webpack/package.json +++ b/src/React.Sample.Webpack/package.json @@ -1,21 +1,21 @@ -{ - "name": "React.Sample.Webpack", - "version": "0.0.1", - "description": "Webpack + ASP.NET MVC 4 sample for ReactJS.NET", - "main": "gulpfile.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "build": "webpack" - }, - "author": "", - "license": "BSD", - "devDependencies": { - "babel-core": "^6.3.17", - "babel-loader": "^6.2.0", - "babel-preset-es2015": "^6.3.13", - "babel-preset-react": "^6.3.13", - "babel-preset-stage-0": "~6.5.0", - "expose-loader": "^0.7.1", - "webpack": "^1.12.9" - } -} +{ + "name": "React.Sample.Webpack", + "version": "0.0.1", + "description": "Webpack + ASP.NET MVC 4 sample for ReactJS.NET", + "main": "gulpfile.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "build": "webpack" + }, + "author": "", + "license": "BSD", + "devDependencies": { + "babel-core": "^6.3.17", + "babel-loader": "^6.2.0", + "babel-preset-es2015": "^6.3.13", + "babel-preset-react": "^6.3.13", + "babel-preset-stage-0": "~6.5.0", + "expose-loader": "^0.7.1", + "webpack": "^1.12.9" + } +}