Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Ag-grid cell renderer with Mitt #171

Closed
Dhaxor opened this issue Nov 14, 2022 · 1 comment
Closed

Using Ag-grid cell renderer with Mitt #171

Dhaxor opened this issue Nov 14, 2022 · 1 comment

Comments

@Dhaxor
Copy link
Contributor

Dhaxor commented Nov 14, 2022

A cell renderer is just like a custom component in an ag-grid table which can be a button, badge, image in a table row. Now I'm using mitt to emit and event from the cell renderer and listening on the parent component when it's rendered. But the issue here is that the cell renderer is used in multiple components so when I listen on each component, they all run. How do I make it listen on just one component at a time.

Cell Renderer

	onChange(event: Event): void {
		this.$eventBus.emit('switchBoxChanged',
			{
				event,
				params: this.params,
			});
	 }

Parent Component

  mounted() {
  	switchBoxChanged(): void {
		this.$eventBus.on('switchBoxChanged',
			(data: SwitchDataType) => {
					httpClient
						.post('/api/data',
							{
								...data,
							})
					}}
  
  }

Another Parent component

mounted() {
  	switchBoxChanged(): void {
		this.$eventBus.on('switchBoxChanged',
			(data: SwitchDataType) => {
					httpClient
						.post('/api/data',
							{
								...data,
							})
					}}
  
  }

Since it's used in multiple components, then when one parent component runs, the other runs too

@Dhaxor
Copy link
Contributor Author

Dhaxor commented Nov 15, 2022

I found the issue. I initialized the event Bus on a global scope. so i had to change that.

@Dhaxor Dhaxor closed this as completed Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant