Scoping of UserEvents confusing

I find the scoping of UserEvents confusing, I get that it works the same way as variables, but it requires that the parent knows what members are defined in the component used. Also since the component calls the MyEvent.raise() it isn’t obvious why one has invoked a component local function since the name is set in the parent component. I.e.

<SearchInput>
      <OnUserEvent EventName="OnSearch" Handler="{onSearch}" />
</SearchInput>

When calling OnSearch.raise()we could be calling onSearch in the SearchInput components function when we intended to call onSearch of the parent. One ends up with really funky naming to avoid this. Is this behavior changeable?

Hi,

I’m not able to decipher your question.

Can you please provide a more complete example to illustrate? Perhaps try to rephrase?

When calling OnSearch.raise() we could be calling onSearch in the SearchInput components function when we intended to call onSearch of the parent. One ends up with really funky naming to avoid this. Is this behavior changeable?

This sounds like a more general issue than something specific to UserEvent.

In general, it is good practice to wrap your internal JavaScripts in another scope, if you don’t want inner functions of your component to be visible to the users of your component, e.g.:

<Panel ux:Class="SearchInput">
    <Panel>
        <JavaScript> 
           // code goes here

It’s only a real issue when you want to invoke callbacks through events because the call is made from the inner most scope and the target callback is alway in a the parent scope.

Your solution works perfectly, I think you should add that to the docs on UserEvents because it also helps understand scoping and how it relates to the markup. Coming from React.js my initial take on components was that they were isolated.