queckezz/koa-views

Why don't you assign "locals" to "ctx.state"?

fengxinming opened this issue · 5 comments

origin:
const state = Object.assign(locals, options, ctx.state || {})

turn into:
const state = Object.assign({}, options, ctx.state || {}, locals)
Would it be better?

@fengxinming hi, any case to prove ?

@int64ago for example:
state.title = '1';
ctx.render('index', {title: 2});

#{ title } => title === '1'

@fengxinming Hi, I think this is a break change, and options should not be covered by locals

@int64ago or locals cover options

const state = Object.assign(locals, options, ctx.state || {})

may lead bug when locals is contained (directly or indirectly) by ctx.state.

I think

const state = Object.assign({}, locals, options, ctx.state || {})

is more safe for client code.