-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(registerObserver): preserve observer
reference
#48
Conversation
const registerObserver = (params, callback) => { | ||
params = params || {} | ||
|
||
// TODO: Is there any way to polyfill this API ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a devtool for chrome + firefox. no need to polyfill.
Writing add-ons/extensions for IE is a whole different problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #52, we'll polyfill for older browsers if we somewhen find a proper polyfill for the API :)
src/npm/hook.js
Outdated
window.__REACT_PERF_DEVTOOL_GLOBAL_STORE__ = { | ||
measures, | ||
length: list.getEntries().length, | ||
rawMeasures: list.getEntries() | ||
} | ||
|
||
// For logging to console |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the if-statement function name clearly indicates that we are logging to console. a comment on this is superfluous
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! Yup, totally.
78d8de8
to
2c5fc45
Compare
I think if we go for |
This is exactly what I had in mind when I discussed return {
// raw oberserver with it's API
observer,
// list of entries that were already processed with
// `generateDataFromMeasures` and `getReactPerformanceData`
// by react-perf-devtool
compiledMeasurements,
} which would serve the two main purposes with this change:
hmm.. I realised now that yes, you're right. You're right because the problem with my suggestion is that consumer can not receive new measurements as soon as they are updated. let's leave this as is. please review :) |
I'll review your PR soon (by the end of this week). I am just busy doing interviews for full-time gig. Although the code changes looks good to me but I'll still pull the changes manually on my machine for behavioural testing. Thank you for all the contribution you've made to this project. I really appreciate your help 😄 |
... 24 days later ... 😆 🤣 |
src/npm/hook.js
Outdated
}) | ||
observer.observe({ entryTypes: ['measure'] }) | ||
return observer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you should then also adapt the README as in #26 to make sure the user declares the observer in the global scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, tested locally aswell!
observer
when callingregisterObserver
Tech debt
logToConsole
takeRecords
or another option overcallback
One problem I found with the current implementation of passing
callback
intowindow.PerformanceObserver
is that we "leaking" or "imposing" external functions into the instantiation ofwindow.PerformanceObserver
, which makes it hard or rather unintuitive to mock and test. One option to consider over this is to return a promise resolving the entries of the observer, but this is anti-pattern to Observers in general. A more optimal solution is a follow up and continuation to returning the instance is havingcallback
removed and allow consumers toregisterOberserver
to usetakeRecords
which fulfills two purpose: