Skip to content

Commit

Permalink
现在app.execute()只能在server端上使用,client端请使用component/App和component/Page
Browse files Browse the repository at this point in the history
  • Loading branch information
lupengyu committed Oct 13, 2015
1 parent f7cbe3d commit 040748f
Showing 1 changed file with 3 additions and 30 deletions.
33 changes: 3 additions & 30 deletions lib/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ function App(options) {
*/
App.prototype.execute = function (request, initialState, needRawState) {

invariant(env.isServer, 'App.execute() must run on server');

/**
* @event module:events~app-request
*/
Expand All @@ -77,16 +79,7 @@ App.prototype.execute = function (request, initialState, needRawState) {
// 加载初始化数据
.then(function (Page) {

// 如果是 client 端,那么这里需要判断一下当前 page 与 nextPage 是否为同一个类型
// 如果是同一类型,那么需要复用当前的 page
// 原因是同一类型的 page 会使用同一类型的 view
// 那么 react 再次渲染时就会认为这是一个 update,而不是重新渲染
// 也就不会触发 componentDidMount,导致相关的 listener 不会被正确添加
// 否则,新生成一个 page 实例
var page = env.isClient && me.page instanceof Page
? me.page
: new Page(initialState);

var page = new Page(initialState);

return Promise
// 这里一定要用 Promise 包裹一下,这个接口可以返回 Promise 或者是 *
Expand Down Expand Up @@ -127,26 +120,6 @@ App.prototype.execute = function (request, initialState, needRawState) {

}

if (env.isClient) {

// 在客户端上,我们需要做更多的事情
// 如果当前正在展现的页面,那么把它销毁掉
if (me.page && me.page !== page) {

me.page.dispose();

/**
* @event module:events~app-page-switch
*/
events.emit('app-page-switch-succeed');

}

// 记录一下当前页面
me.page = page;

}

/**
* @event module:events~app-page-bootstrap
*/
Expand Down

0 comments on commit 040748f

Please sign in to comment.