These are chat archives for canjs/canjs

1st
Jul 2015
neelbhat88
@neelbhat88
Jul 01 2015 16:33
Anyone know the best way to solve this in CanJS? I have multiple components that all need the same function - isLoggedIn() for example. Right now I've needed to copy that function into every component which feels very wrong. My gut reaction was to put that in my main component assuming it acts as a parent to all other components and assuming child components inherit from the parent. But I'm pretty sure those assumptions are not correct. Any tips on how to correctly do this is much appreciated!
dylanrtt
@dylanrtt
Jul 01 2015 16:36
@neelbhat88 your child components will inherit their parent scopes by default unless you set leakScope: false in your component definition
a better way, which also works without leaking scope, would be to pass it to the child components
there may also be value in simply extracting the function to an outside service if possible and including it in all of your components that need it
neelbhat88
@neelbhat88
Jul 01 2015 16:46
@dylanrtt - Thanks! We haven't set leakScope: false anywhere so let me double check and see why the child was not inheriting from the parent scope. I did just notice that my isLoggedIn was set as a variable on the parent scope and not as a function - maybe that's it? I'll find out. At least knowing that child components should inherit their parent scopes is all I need - I'm sure I'm doing something else wrong then. Thanks again!
Aggelos Karalias
@mehiel
Jul 01 2015 18:51
Any ideas why partials with can-value inside do re-render as a whole when the bound value is changing?
I'll try to create a fiddle
dylanrtt
@dylanrtt
Jul 01 2015 19:10
@mehiel that might be related to #1759
Aggelos Karalias
@mehiel
Jul 01 2015 19:16
yes
Aggelos Karalias
@mehiel
Jul 01 2015 19:22
I removed the compute wrapping for now in mustache_core.js:391 to make it work.. but this is a brute force workaround that probably breaks lots of other things..
I'll try to dig deeper in that and see if there's a way to make it work as expected with can-value's in there..
Matthew Phillips
@matthewp
Jul 01 2015 20:56
can-value is defined in can/view/bindings
i doubt that's related to the bug though