These are chat archives for canjs/canjs

10th
Mar 2017
Jeroen Cornelissen
@jeroencornelissen
Mar 10 2017 11:04
I have cross-posted my question on the forums, so it wouldn’t get lost in this channel:
http://forums.donejs.com/t/bulk-actions-destroy-update-on-multiple-items/575
Justin Meyer
@justinbmeyer
Mar 10 2017 16:35
deepasrikanth
@deepasrikanth
Mar 10 2017 21:22
hi I have a question regarding components. I have a generic component that I would like to use from other components
This generic component will display a small ui with buttons where the click handler will be implemented in the component that is consuming the generic component.
though I am able to pass the callback function name as the click handler, it appears that the scope is not clear. When I execute the code its looking for the callback implementation in the generic component where as its available in the context its being called. How can I address this?
Kevin Phillips
@phillipskevin
Mar 10 2017 21:24
you’ll want to pass the function in to the generic component
deepasrikanth
@deepasrikanth
Mar 10 2017 21:24
I am passing function name. The function is in the viewModel of the calling component . Are you suggesting that I should pass the function code itself?
Kevin Phillips
@phillipskevin
Mar 10 2017 21:25
so in the parent component, do something like <generic-component {handler}=“@clickHandler” />
and then in the generic-component, you’ll do ($click)=“handler()”
is that what you’re doing now?
deepasrikanth
@deepasrikanth
Mar 10 2017 21:26
yes
Kevin Phillips
@phillipskevin
Mar 10 2017 21:27

let me make my names more clear. In the parent component:

<generic-component {generic-click-handler}=“@parentClickHandler” />

and then in the generic-component template:

($click)=“genericClickHandler()
deepasrikanth
@deepasrikanth
Mar 10 2017 21:29
ok generic-click-handler is not a function in the generic component. I have that as a property. If I change that as a function that should fix it ?
Kevin Phillips
@phillipskevin
Mar 10 2017 21:30
in the genericComponent viewModel it will just be a property that you can overwrite, like
GenericComponentViewModel = can.DefineMap.extend({
    genericClickHandler: 'any'
});
deepasrikanth
@deepasrikanth
Mar 10 2017 21:32
trying that
that worked than you very much :)
*thank
Kevin Phillips
@phillipskevin
Mar 10 2017 21:37
you’re welcome. glad it worked!