-
-
Save renemonroy/4ebcee2e9baf98d9d4b3 to your computer and use it in GitHub Desktop.
Revisions
-
julik revised this gist
Jan 28, 2014 . 1 changed file with 16 additions and 11 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,29 +1,34 @@ # A module that allows us to send Backbone events up the tree of components ReactTelegraph = componentWillMount: -> # Make BB events available to the component _.extend @, Backbone.Events componentWillUnmount: -> # Remove all Backbone event listeners @off null, null, null # Shortcut for triggerWithBubbling upstream: (ar...)-> @triggerWithBubbling(ar...) triggerWithBubbling: (ar...)-> # Trigger the event on myself using partial application @trigger.bind(@, ar...)() # And telegraph the event up the component tree parent = @props.__owner__ # Only do this if the owner component responds to "triggerWithBubbling" # - the extension indicates that the component participates in the # Telegraph system and has the mixin if parent and parent.triggerWithBubbling parent.triggerWithBubbling(ar...) # Return self @ window.ReactTelegraph = ReactTelegraph MyButton = React.createClass mixins: [ReactTelegraph] -
julik renamed this gist
Jan 18, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
julik revised this gist
Jan 18, 2014 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,8 +2,7 @@ ReactTelegraph = componentDidMount: -> _.extend @, Backbone.Events componentDidUnmount: -> @off null, null, null -
julik revised this gist
Jan 18, 2014 . 1 changed file with 10 additions and 11 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,12 @@ # A module that allows us to send Backbone events up the tree of components ReactTelegraph = componentDidMount: -> _.extend @, Backbone.Events _.extend @, ReactTelegraph componentDidUnmount: -> @off null, null, null triggerWithBubbling: (ar...)-> return unless @trigger @@ -20,32 +27,24 @@ ReactTelegraph = true MyButton = React.createClass mixins: [ReactTelegraph] upvoteClicked: -> @triggerWithBubbling 'upvote', @props.commentId render: -> (button {onClick: @upvoteClicked}, "Upvote comment #{@props.commentId}!") MyComponent = React.createClass mixins: [ReactTelegraph] render: -> (div {}, (MyButton {commentId: 123}), (MyButton {commentId: 234})) componentDidMount: -> # Listen to the "upvote" # event via BB events, it's going to be # sent from one of the children @on 'upvote', (cid) -> # Do whatever we have to do console.debug "Comment #{cid} upvoted" -
julik revised this gist
Jan 18, 2014 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,11 @@ MyButton = React.createClass render: -> (button {onClick: @upvoteClicked}, "Upvote comment #{@props.commentId}!") componentDidMount: -> _.extend @, Backbone.Events _.extend @, ReactTelegraph MyComponent = React.createClass render: -> (div {}, (MyButton {commentId: 123}), (MyButton {commentId: 234})) -
julik revised this gist
Jan 18, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -28,7 +28,7 @@ MyButton = React.createClass MyComponent = React.createClass render: -> (div {}, (MyButton {commentId: 123}), (MyButton {commentId: 234})) componentDidMount: -> _.extend @, Backbone.Events -
julik created this gist
Jan 18, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ # A module that allows us to send Backbone events up the tree of components ReactTelegraph = triggerWithBubbling: (ar...)-> return unless @trigger # Trigger on myself using partial application @trigger.bind(@, ar...)() # And telegraph the event up the component tree parent = @props.__owner__ return unless parent # Only do this if the owner component responds to "triggerWithBubbling" # - the extension indicates that the component participates in the # Telegraph if parent.triggerWithBubbling parent.triggerWithBubbling(ar...) # Return true true MyButton = React.createClass upvoteClicked: -> @triggerWithBubbling 'upvote', @props.commentId render: -> (button {onClick: @upvoteClicked}, "Upvote comment #{@props.commentId}!") MyComponent = React.createClass render: -> (div {}) componentDidMount: -> _.extend @, Backbone.Events _.extend @, ReactTelegraph # Listen to the "upvote" # event via BB events, it's going to be # sent from one of the children @on 'upvote', (cid) -> # Do whatever we have to do console.debug "Comment #{cid} upvoted" componentDidUnmount: -> # Remove BB events @off(null, null, null)