-
Notifications
You must be signed in to change notification settings - Fork 26
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
PerformanceObserver's observe() should support entryType-specific parameters #103
Comments
This PR adds a PerformanceEntryObserverOptions dictionary where entryType-specific parameters are used. The buffered flag is moved to this dictionary. Some <i> tags are changed to <var>. Observe() is updated to consider dictionaries. Queueing an entry is modified to allow passing in a closure. This is in preparation for adding thresholds to certain entry types. Solves w3c#103
So the whole *Observer pattern is that you're supposed to call I think a better interface would be to make observe(~) take "type" and other options directly as in: observe.observe({entryTypes: ["resource"]});
observe.observe({type: 'longtask', buffered: true, threshold: 100}); |
We already allow observe to take multiple things to observe. And if there are multiple calls to observe() I think that currently we override what we observe, not append to it. |
The fact PerformanceObserver behaves so differently from other *Observer pattern is bad. We shouldn't make it worse. We can make it so that we support both modes. When multiple times are specified, simply replace the observed list. When a single type is specified, it appends or replaces an existing entry of the same type using new options. |
Hmm.. Our earlier proposal was predicated on assumption that folks want to use a single observer to monitor for multiple types, each with potentially different settings. On the WG call, I think we identified that this may not be the best pattern, or pattern we want to encourage. Instead of observing many different types and building a switch statement, create multiple distinct observers. Given that, WDYT of... observe.observe({entryTypes: ["resource", "navigation"], buffered: true, threshold: 100}); Observe observe.observe({entryTypes: ["mark"], buffered: true});
observe.observe({entryTypes: ["longtask"], buffered: true, threshold: 50}); If you want to observe different types with different settings, create multiple observers? Perhaps we can just stick with |
It seems to me that allowing a single observe() call to specify multiple entryTypes and also various settings is prone to errors if the names of the settings are shared but they mean different things for different entryTypes. Thus, a developer could do: |
Yeah, I don't think we should use |
I don't understand the concern. If you plan to observe multiple entryTypes, you would specify multiple-or-maybe-one and you can use Maybe there's a valid use case of specifying the I think sticking with always having @toddreifsteck @yoavweiss may also have thoughts on this discussion. |
@npm1 : I'm saying that changing the behavior of I would strongly object to add options support with |
@rniwa to clarify, you're saying... observe.observe({entryTypes: ["resource"]}); // A
observe.observe({type: 'longtask', buffered: true, threshold: 100}); // B
|
@igrigorik : Sort of. I would prefer if |
Hmm, we already spec'ed E.g. I'm an analytics vendor that, once loaded, wants to suck up all the buffered entries. If we drop What's your thinking against supporting global flags? |
Also how do you propose we specify this on the IDL? I played with it and it looks like this is invalid due to both being dictionaries (you can't overload like that): |
And that analytic vendor doesn't want to write a single line code like this?:
For a better consistency. |
Just have a single dictionary which defines both |
A single definition of observe sounds good. In this case, WDYT of having |
I don't we want a thing named |
@igrigorik WDYT? If you're ok with this proposal I can send out a new PR. With the understanding that I plan to add entries such as |
I do suspect this will be a pretty common pattern replicated across many scripts, but fair enough, I don't have any strong objections. @nicjansma @philipwalton any strong feelings on this one? @npm1 overall, lgtm, I think @rniwa's points all make sense. As an aside, with this pattern we need to land |
I can believe that. But I think being consistent across *Observer API will improve the overall developer ergonomics of the web platform as a whole. Using the same pattern in many different parts of the platform would reduce the cognitive stress of understanding Web API in general. |
No strong feelings. The way we're consuming PO is very context-specific (e.g. different analytics components register their own observer for things they care about), instead of asking for all types at once, or needing to specify multiple entryTypes at once. |
@rniwa yep, fair points. Sounds like we have consensus.. Let's make it happen. :) |
Discussed at TPAC F2F: |
This change introduces a DOMString type in PerformanceObserverInit to support observing a single entryType with other parameters from the dictionary. The change modifies the observe() method so that: * observe({entryTypes:...}) is still supported but not with any other member of the PerformanceObserverInit dictionary. * observe({type: ...}) is now supported, and multiple calls stack. * Both ways to call observe() cannot be mixed. That is, an observer has to stick to one of the ways, and 'observer type' is introduced to enforce this. In addition, some nits are fixed along the way, such as using <var> and <a> appropriately throughout. Solves w3c#103
Forgot to close this. |
Currently, observe() gets a sequence of entryTypes and optionally a boolean buffered flag. I'd like to augment this as follows:
The entryTypes could be used alongside entryType-specific parameters. For example, a user could say:
observer.observe({entryTypes: ["resource"], longtask: {buffered: true, threshold: 100} });
The text was updated successfully, but these errors were encountered: