These are chat archives for canjs/canjs

19th
Feb 2017
Nils Lundquist
@nlundquist
Feb 19 2017 21:54

hey all, I've got an issue with 2.3 that I'm wondering if anyone is familiar with:

trying to pass a function from a parent component to a child with a binding like {on-my-event}="@eventHandler" but since the child component is using a can.Map with a define, eventHandler is set as the define value property for onMyEvent and any define value function prop is called as if it's a value defaulter function. see the code around: https://github.com/canjs/canjs/blob/2.3-legacy/map/define/define.js#L45

only solution i can come up with is to pass the child component a function that returns the function i actually want to use as the value of the prop, but that seems like a pretty sad hack for something so simple.
Nils Lundquist
@nlundquist
Feb 19 2017 21:59
def not intuitive to require a parent component to pass a child component wrapped functions to prevent this from happening
Justin Meyer
@justinbmeyer
Feb 19 2017 22:03
@nlundquist if you want a default property value that is a function, the only way is to create a function that returns a function
but I'm not sure I understand you right
what you linked to only deals with maps ... seems like there's something around view bindings
Nils Lundquist
@nlundquist
Feb 19 2017 22:11

hey Justin. I don't need a default value. I'm fine with the default property requiring a function to return a function since that's all in the view model config of the child. What I'm trying to do is pass a function from a parent component to a child component, and use that function within the child component logic.

Right now, whenever I pass a component from the parent component to the child component, the child component calls that function during it's a initialization because it thinks that function is a 'defaulter()' value like mentioned in the docs here: https://v2.canjs.com/docs/can.Map.prototype.define.value.html

I don't think there is an issue with the view bindings since the function is successfully passed from the parent component to child. The function is set on the child VM, in my example case, as the value on the onMyEvent property of the VM.

I just don't want that passed value to be called during child component VM initialization. The map/define/define.js code I linked to is where this function is added to the set of Map.defaultGenerators
I want to avoid that happening since i'm not passing a function for use as a default value generator, I'm passing it for use inside the child component logic
Nils Lundquist
@nlundquist
Feb 19 2017 22:17
@justinbmeyer if what i'm trying to accomplish is still unclear lets jump on a screenshare