-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
264 additions
and
13,068 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
module.exports = app => { | ||
return class DataController extends app.Controller { | ||
|
||
async nodeDataRender(ctx) { | ||
const title = 'Node 直接获取渲染数据'; | ||
const article = await ctx.service.article.getArticle(1); | ||
await ctx.render('example/node.js', { title, article }); | ||
} | ||
|
||
async asyncDataRender(ctx) { | ||
const title = '前端 React 代码 asyncData 获取渲染数据'; | ||
await ctx.render('example/data.js', { title }); | ||
} | ||
|
||
async article(ctx) { | ||
const article = await ctx.service.article.getArticle(1); | ||
ctx.body = { article }; | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
module.exports = app => { | ||
return class ExampleController extends app.Controller { | ||
|
||
async asyncComponentRender(ctx) { | ||
await ctx.render('async.js', { message: 'Egg React Server Side Async Component Render' }); | ||
} | ||
|
||
async statelessRender() { | ||
const { ctx } = this; | ||
await ctx.render('example/stateless.js', { | ||
text: 'React Stateless Component Server Render' | ||
}); | ||
} | ||
|
||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
|
||
module.exports = app => { | ||
const { router, controller } = app; | ||
router.get('/api/list', controller.home.index.list); | ||
router.get('/api/blog/list', controller.blog.index.list); | ||
router.get('/api/blog/:id', controller.blog.index.detail); | ||
router.get('/intro', controller.intro.intro.index); | ||
router.get('/detail/:id', controller.home.index.detail); | ||
router.get('/csr', controller.home.index.csr); | ||
router.get('/node', controller.home.index.node); | ||
router.get('/stateless', controller.home.index.stateless); | ||
router.get('/test/async', controller.test.test.asyncComponentRender); | ||
router.get('/test/data', controller.test.test.asyncDataRender); | ||
router.get('/test/api/article', controller.test.test.article); | ||
router.get('/*', controller.home.index.ssr); | ||
router.get('/csr', controller.blog.index.csr); | ||
router.get('/node', controller.blog.index.node); | ||
router.get('/example/stateless', controller.example.index.statelessRender); | ||
router.get('/example/async', controller.example.index.asyncComponentRender); | ||
router.get('/example/data/node', controller.example.data.nodeDataRender); | ||
router.get('/example/data/async', controller.example.data.asyncDataRender); | ||
router.get('/example/data/api/article', controller.example.data.article); | ||
router.get('/(.*?)', controller.blog.index.ssr); | ||
}; |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { hot } from 'react-hot-loader/root' | ||
|
||
import request from '../../../framework/request'; | ||
|
||
class Detail extends Component { | ||
static async asyncData(locals, route) { | ||
const id = route.match.params.id; | ||
return request.get(`/api/blog/${id}`, locals); | ||
} | ||
|
||
render() { | ||
const { article } = this.props; | ||
return article ? <div> | ||
<h2 className="easy-article-detail-title">{article.title}</h2> | ||
<div className="easy-article-info"> | ||
<iframe src={article.url} frameBorder="0" width="100%" style={{minHeight: '800px'}}></iframe> | ||
</div> | ||
</div> : null; | ||
} | ||
} | ||
|
||
|
||
const mapStateToProps = state => { | ||
return { | ||
article: state.article | ||
}; | ||
}; | ||
|
||
export default connect(mapStateToProps)(EASY_ENV_IS_DEV ? hot(Detail) : Detail) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import React, { Component } from 'react'; | ||
|
||
export default class Example extends Component { | ||
|
||
render() { | ||
const styleTitle = { | ||
marginTop: '40px', marginBottom: '40px', textAlign: 'center' | ||
}; | ||
const styleSub = { | ||
marginBottom: '40px', textAlign: 'center', color: '444444' | ||
}; | ||
return <div> | ||
<h2 style={{...styleTitle}}>Egg React Example</h2> | ||
<h4 style={{...styleSub}}><a target="_blank" href="/example/async">React Async Component Render</a></h4> | ||
<h4 style={{...styleSub}}><a target="_blank" href="/example/stateless">React Stateless Component Render</a></h4> | ||
<h4 style={{...styleSub}}><a target="_blank" href="/example/data/node">React Server Render for Node Data Mode</a></h4> | ||
<h4 style={{...styleSub}}><a target="_blank" href="/example/data/async">React Server Render for asyncData Mode</a></h4> | ||
</div>; | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
import React, { Component } from 'react'; | ||
import { Route } from 'react-router-dom'; | ||
import { connect } from 'react-redux'; | ||
import { update } from '../store/actions'; | ||
|
||
class WrapperRoute extends Component { | ||
|
||
async componentWillReceiveProps(nextProps) { | ||
const { type, locals, component, computedMatch, updateState } = nextProps; | ||
console.log('>>route', computedMatch.url, this.props.computedMatch.url); | ||
if (computedMatch.url !== this.props.computedMatch.url) { | ||
const { asyncData } = component; | ||
if (asyncData) { | ||
const data = await asyncData(locals, { match: computedMatch }); | ||
console.log('>>>update', type, data); | ||
updateState(type, data); | ||
} | ||
} | ||
} | ||
|
||
render() { | ||
return <Route {...this.props} /> | ||
} | ||
} | ||
|
||
const mapStateToProps = state => { | ||
return { | ||
locals: state | ||
} | ||
}; | ||
|
||
const mapDispatchToProps = dispatch => { | ||
return { | ||
updateState: (type, data) => dispatch(update(type, data)) | ||
}; | ||
}; | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(WrapperRoute); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const update = (type, data) => { | ||
return { | ||
type, | ||
data | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const ARTICLE_LIST = 'ARTICLE_LIST'; | ||
export const ARTICLE_DETAIL = 'ARTICLE_DETAIL'; | ||
export const ADD = 'ADD'; | ||
export const DEL = 'DEL'; |
File renamed without changes.
Oops, something went wrong.