How to call an event in my custom component from the UI Builder

Philippe Luickx
Tera Contributor

I have created a custom component and I want to trigger an event in that component from the UI Builder. Is it possible to call that event? I tried api.emit('EVENT') in a client script but that didn't work.

Otherwise I would have to watch a property? But not sure if that's even possible?

1 ACCEPTED SOLUTION

Ahh so components are built as properties in and events out, so I would expose a property that you want to monitor and then use your event in UIB to change a CSP you've bound to that property in UIB.

View solution in original post

6 REPLIES 6

Just found about COMPONENT_PROPERTY_CHANGED and this seems to tie it all nicely together.

So basically, property changes and this can be "watched" to react on it.

 

	    [COMPONENT_PROPERTY_CHANGED]({dispatch, action: {payload: {name, value, previousValue}}}) {

			if (name === 'property_name') {
				dispatch(EVENT);
			}
		},

@Philippe Luickx It's aIso possible to listen for property changes by declaring the property this way

mapItemMarkers: {
    default: DEFAULT_VALUES,
    onChange(currentValue, previousValue, dispatch) {
        dispatch(customActions.INITIALIZE_MAP);
    }
}

PS: I am also building a custom map component.