Comment WithEmit

This commit is contained in:
Chi Vinh Le
2017-07-22 00:10:45 +07:00
parent 7b1c0dfbaa
commit 1db61941ed
+6 -2
View File
@@ -1,14 +1,18 @@
import React from 'react';
const PropTypes = require('prop-types');
/**
* WithEmit provides a property `emit: (eventName, value)`
* to the wrapped component.
*/
export default (WrappedComponent) => {
class WithEmit extends React.Component {
static contextTypes = {
eventEmitter: PropTypes.object,
};
emit = (eventName, value, context) => {
this.context.eventEmitter.emit(eventName, value, context);
emit = (eventName, value) => {
this.context.eventEmitter.emit(eventName, value);
};
render() {