Skip to content

Instantly share code, notes, and snippets.

@alexkirsz
Created April 21, 2014 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexkirsz/11130007 to your computer and use it in GitHub Desktop.
Save alexkirsz/11130007 to your computer and use it in GitHub Desktop.
Example use of EventMixin
Button = react.createClass
displayName: 'Button'
mixins: [EventMixin]
handleClick: ->
@emit 'click'
@bubble 'dropdown.open', x: 10, y: 20 # Bubble the event up the component chain
render: ->
dom.div className: 'Button', onClick: @handleClick
Frame = react.createClass
displayName: 'Frame'
mixins: [EventMixin]
componentDidMount: ->
# Communication between component to owner
@refs.button.on 'click', ->
console.log 'button clicked'
render: ->
dom.div className: 'Frame', [
Button ref: 'button'
]
App = react.createClass
displayName: 'App'
mixins: [EventMixin]
componentDidMount: ->
# Communication between distant components
@on 'dropdown.open', (e) ->
console.log "open dropdown at pos #{e.args[0].x},#{e.args[0].y}"
e.stopPropagation() # Stops propagation of the event.
render: ->
dom.div className: 'App', [
Frame()
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment