Last active
October 5, 2015 14:49
-
-
Save sunify/b7d78fc7e915c5e361ea to your computer and use it in GitHub Desktop.
React mixin
This file contains 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
var handlers = {}; | |
document.addEventListener('click', onDocumentClick); | |
function onDocumentClick(evt) { | |
var rid = (evt.target.dataset && evt.target.dataset.reactid) || ''; | |
Object.keys(handlers).forEach(function(key) { | |
var hnd = handlers[key]; | |
if(rid.indexOf(key) !== 0) { | |
hnd.comp[hnd.handler](evt); | |
} | |
}); | |
}; | |
module.exports = function(handlerName) { | |
return { | |
componentDidMount: function() { | |
if(this[handlerName]) { | |
handlers[this._rootNodeID] = { | |
comp: this, | |
handler: handlerName | |
}; | |
} | |
}, | |
componentWillUnmount: function() { | |
delete handlers[this._rootNodeID]; | |
} | |
}; | |
}; |
This file contains 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
React.createClass({ | |
mixins: OnOutClickMixin('onOutClick'), | |
onOutClick: function() { | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment