supermedium / aframe-react

:atom: Build virtual reality experiences with A-Frame and React.
https://ngokevin.github.io/aframe-react-boilerplate/
MIT License
1.42k stars 151 forks source link

Detach Events #39

Closed azmartone closed 7 years ago

azmartone commented 8 years ago

We need a way to remove the events that get attached to the element.

            <Entity
                onMouseEnter={this.onMouseEnter}
                onMouseLeave={this.onMouseLeave}
                onClick={this.onClick}
                >
azmartone commented 8 years ago

Actually, those props are from aframe-mouse-cursor-component

ngokevin commented 8 years ago

That is true though, we do need to detach event props when those props are removed.

jesstelford commented 8 years ago

An idea on that front: Store the event map as a component property (this._eventMap), then only attach a single event listener (regardless of if this._eventMap has any values or not), then inside the event listener, the event name becomes the key into this._eventMap.

We'd need to also add a componentWillReceiveProps() to regenerate the this._eventMap object, then everything else is handled without having to update anything or add / remove any event listeners.

ngokevin commented 7 years ago

v4.0.x will now diff the events map and register/deregister as necessary.