Created
May 24, 2019 11:35
-
-
Save paularmstrong/8e065f1160a2f66178df47a4a23c887f to your computer and use it in GitHub Desktop.
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
export default function(target) { | |
const originalMethods = { | |
UNSAFE_componentWillMount: target.prototype.UNSAFE_componentWillMount || noop, | |
componentDidMount: target.prototype.componentDidMount || noop, | |
UNSAFE_componentWillUpdate: target.prototype.UNSAFE_componentWillUpdate || noop, | |
componentDidUpdate: target.prototype.componentDidUpdate || noop, | |
componentWillUnmount: target.prototype.componentWillUnmount || noop | |
}; | |
target.prototype.UNSAFE_componentWillMount = function(...args) { | |
const [name, identifier] = getIdentifiers(this, true); | |
originalMethods.UNSAFE_componentWillMount.apply(this, args); | |
recordTimestamp(name, identifier, 'willMount', Date.now()); | |
}; | |
target.prototype.componentDidMount = function(...args) { | |
const [name, identifier] = getIdentifiers(this); | |
originalMethods.componentDidMount.apply(this, args); | |
recordTimestamp(name, identifier, 'didMount', Date.now()); | |
throttledRecordMetrics(); | |
}; | |
target.prototype.UNSAFE_componentWillUpdate = function(...args) { | |
const [name, identifier] = getIdentifiers(this, true); | |
originalMethods.UNSAFE_componentWillUpdate.apply(this, args); | |
recordTimestamp(name, identifier, 'willUpdate', Date.now()); | |
}; | |
target.prototype.componentDidUpdate = function(...args) { | |
const [name, identifier] = getIdentifiers(this); | |
originalMethods.componentDidUpdate.apply(this, args); | |
recordTimestamp(name, identifier, 'didUpdate', Date.now()); | |
throttledRecordMetrics(); | |
}; | |
target.prototype.componentWillUnmount = function(...args) { | |
originalMethods.componentWillUnmount.apply(this, args); | |
throttledRecordMetrics(); | |
}; | |
return target; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment