Created
April 21, 2014 01:45
-
-
Save alexkirsz/11130007 to your computer and use it in GitHub Desktop.
Example use of EventMixin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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