antonmedv / monkberry

Monkberry is a JavaScript library for building web user interfaces
https://monkberry.js.org
MIT License
1.49k stars 78 forks source link

Render context #11

Closed benjamminf closed 8 years ago

benjamminf commented 8 years ago

I'm not sure exactly what the purpose of the context parameter is when rendering templates. In the API reference, the only note on this parameter is:

This will pass through every component hierarchy

Does this mean any descendant components initialised in the rendered template will have the context data passed to it as well?

My first thought was that context provided a way of passing in extra "global" properties that could be used in templates. After looking through the source I realised this wasn't the case, so I modified my update methods in all my components like so:

update(state)
{
    Object.assign(this.state, state)
    super.update(Object.assign({}, this.context, this.state))
}

Is this an appropriate use of the context parameter?

benjamminf commented 8 years ago

Looking into some examples, I see context is generally used to hold actions for state management (redux). This is a much better idea.

antonmedv commented 8 years ago

Hi,t

You are right, context is for passing some context (😃 ) through component hierarchy. It's same as reacts contexts: https://facebook.github.io/react/docs/context.html

benjamminf commented 8 years ago

Ah okay, thanks! I've never used React before, and as far as I know there's no explicit controlling of component context in Vue. Cheers for the link!