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

Rebuild event listeners when needed #30

Closed
EragonJ opened this issue Aug 25, 2015 · 6 comments
Closed

Rebuild event listeners when needed #30

EragonJ opened this issue Aug 25, 2015 · 6 comments

Comments

@EragonJ
Copy link

EragonJ commented Aug 25, 2015

Hi @wwayne, do you think it is reasonable to let React-Tooltip register a customized event to make sure it can rebuild listeners when needed ?

Right now, ReactToolip only works for pre-existed elements and if the DOM structure is changed, new-added elements will not be handled by this component.

Any idea ?

@wwayne
Copy link
Collaborator

wwayne commented Aug 25, 2015

@EragonJ Good point, thanks.
I don't know if registering a custom event is the best way but it sounds good to me, let me try on it when I have time and welcome PR and advice.

@EragonJ
Copy link
Author

EragonJ commented Aug 25, 2015

I added this for my personal use : EragonJ@599145b

If you are fine with this implementation for better idea, I am willing to help.

@EragonJ
Copy link
Author

EragonJ commented Aug 25, 2015

The main problem is that it's hard to manipulate ReactTooltip from outside of the world (Or is it possible to expose any method for outer use ?)

Some idea from the document : https://facebook.github.io/react/tips/communicate-between-components.html

For communication between two components that don't have a parent-child relationship, you can set up your own global event system. Subscribe to events in componentDidMount(), unsubscribe in componentWillUnmount(), and call setState() when you receive an event. Flux pattern is one of the possible ways to arrange this.

@EragonJ
Copy link
Author

EragonJ commented Aug 25, 2015

or, we can add one extra property for ReactTooltip to let users to decide whether they want to register this global event or not ?

@wwayne
Copy link
Collaborator

wwayne commented Sep 16, 2015

@EragonJ really appreciate for your enlightenment
now users can use ReactTooltip.hide() or ReactTooltip.rebuild() to dispatch global event

import ReactTooltip from 'react-tooltip'

class MyComponent extends React.Component {

onClick() {
  // will dispatch a global event, do unbind then bind 
  ReactTooltip.rebuild()
}

render() {
  <div>
   <a onClick={::this.onClick}>rebuild</a>
   <ReactTooltip />
  </div>

}

}

@wwayne wwayne closed this as completed Sep 16, 2015
@EragonJ
Copy link
Author

EragonJ commented Sep 16, 2015

@wwayne +++ !! Glad to see this patch :P

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

2 participants