       onReleaseOutside: null
       onReleaseInside: null
 
-  handleMouseEnter: -> @setState isInside: true
-  handleMouseLeave: -> @setState isInside: false
+  handleMouseEnter: -> @_isInside = true; return
+  handleMouseLeave: -> @_isInside = false; return
 
   handleMouseDown: ->
     @props.onPress?()

    # Listen for a mouse up somewhere else in case the user presses then moves.
    eventlistener.add document, 'mouseup', @handleDocumentMouseUp

    @setState
      isInside: true
      isPressed: true
  handleMouseUp: ->
    # Call the release event handlers.
    if @state.isPressed
      @props.onRelease?()
      @props.onReleaseInside?()

    @setState isPressed: false

  handleDocumentMouseUp: ->
    # Remove the listener
    eventlistener.remove document, 'mouseup', @handleDocumentMouseUp

    @setState isPressed: false

    # If the mouse isn't inside the object, we need to trigger the release and
    # releaseOutside events.
    unless @state.isInside
      @props.onRelease?()
      @props.onReleaseOutside?()


module.exports = Pressable

  getDefaultProps: ->
    component: div

  componentWillMount: ->
    @_isPressed = false
    @_isInside = false # This will only be accurate while the component is pressed; there's no reason to keep track otherwise.

  render: -> @props.component @getProps(), @props.children

