From 87cc894512d932a3cb0b1fa3b2aec4e153c0abf7 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Thu, 15 Mar 2018 16:16:32 -0300 Subject: [PATCH] Path all React component functions automatically --- client/src/modules/reactcomponents.js | 93 +++++++++++++++++++++------ 1 file changed, 74 insertions(+), 19 deletions(-) diff --git a/client/src/modules/reactcomponents.js b/client/src/modules/reactcomponents.js index a9402163..ab888646 100644 --- a/client/src/modules/reactcomponents.js +++ b/client/src/modules/reactcomponents.js @@ -143,29 +143,78 @@ class ReactComponent { this._component = component; this._retVal = retVal; const self = this; - Patcher.slavepatch(this.component.prototype, 'componentDidMount', function (a, parv) { - self.eventCallback('componentDidMount', { - props: this.props, - state: this.state, - element: Helpers.ReactDOM.findDOMNode(this), + Patcher.slavepatch(this.component.prototype, 'componentWillMount', function(args, parv) { + self.eventCallback('componentWillMount', { + component: this, retVal: parv.retVal }); }); - Patcher.slavepatch(this.component.prototype, 'componentDidUpdate', function(a, parv) { - self.eventCallback('componentDidUpdate', { - prevProps: a[0], - prevState: a[1], - props: this.props, - state: this.state, - element: Helpers.ReactDOM.findDOMNode(this), - retVal: parv.retVal - }); - }); - Patcher.slavepatch(this.component.prototype, 'render', function (a, parv) { + Patcher.slavepatch(this.component.prototype, 'render', function (args, parv) { self.eventCallback('render', { component: this, - retVal: parv.retVal, - p: parv + retVal: parv.retVal + }); + }); + Patcher.slavepatch(this.component.prototype, 'componentDidMount', function (args, parv) { + self.eventCallback('componentDidMount', { + component: this, + props: this.props, + state: this.state, + element: Helpers.ReactDOM.findDOMNode(this), + retVal: parv.retVal + }); + }); + Patcher.slavepatch(this.component.prototype, 'componentWillReceiveProps', function (args, parv) { + const [nextProps] = args; + self.eventCallback('componentWillReceiveProps', { + component: this, + nextProps, + retVal: parv.retVal + }); + }); + Patcher.slavepatch(this.component.prototype, 'shouldComponentUpdate', function (args, parv) { + const [nextProps, nextState] = args; + self.eventCallback('shouldComponentUpdate', { + component: this, + nextProps, + nextState, + retVal: parv.retVal + }); + }); + Patcher.slavepatch(this.component.prototype, 'componentWillUpdate', function (args, parv) { + const [nextProps, nextState] = args; + self.eventCallback('componentWillUpdate', { + component: this, + nextProps, + nextState, + retVal: parv.retVal + }); + }); + Patcher.slavepatch(this.component.prototype, 'componentDidUpdate', function(args, parv) { + const [prevProps, prevState] = args; + self.eventCallback('componentDidUpdate', { + component: this, + prevProps, + prevState, + props: this.props, + state: this.state, + element: Helpers.ReactDOM.findDOMNode(this), + retVal: parv.retVal + }); + }); + Patcher.slavepatch(this.component.prototype, 'componentWillUnmount', function (args, parv) { + self.eventCallback('componentWillUnmount', { + component: this, + retVal: parv.retVal + }); + }); + Patcher.slavepatch(this.component.prototype, 'componentDidCatch', function (args, parv) { + const [error, info] = args; + self.eventCallback('componentDidCatch', { + component: this, + error, + info, + retVal: parv.retVal }); }); } @@ -178,9 +227,15 @@ class ReactComponent { get events() { return this._events || (this._events = [ + { id: 'componentWillMount', listeners: [] }, + { id: 'render', listeners: [] }, { id: 'componentDidMount', listeners: [] }, + { id: 'componentWillReceiveProps', listeners: [] }, + { id: 'shouldComponentUpdate', listeners: [] }, + { id: 'componentWillUpdate', listeners: [] }, { id: 'componentDidUpdate', listeners: [] }, - { id: 'render', listeners: [] } + { id: 'componentWillUnmount', listeners: [] }, + { id: 'componentDidCatch', listeners: [] } ]); }