Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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