-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support koa ctx.state #10
Conversation
*/ | ||
function merge(target, source) { | ||
for (var key in source) { | ||
target[key] = source[key]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!target.hasOwnProperty(key)) {
target[key] = source[key];
}
this.state
不应该覆盖 data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
额,我直接从 koa-ejs 复制的,我改下,没仔细看…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app.context.render = function *(view, _context) {
var context = {};
merge(context, this.state);
merge(context, _context);
这样吧,不改变原来的 data 对象,而且用 data 覆盖 state 的内容
不要在意测试用例的端口号从 9000 -> 4001 了,逃~~~ |
没权限,@yiminghe 发布一下吧 |
done. 权限加了 |
koa 文档:
类似 express 的 locals, 可以在 view 里直接使用的变量,如 user, 而无需每次 render 的时候都需要传入。