-
Notifications
You must be signed in to change notification settings - Fork 298
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
Change DOMTokenList's add() return value. #114
Conversation
Change the return value of add() to have three states: "supported", "not supported" and "no supported tokens". The "validation steps" algorithm return values also change accordingly.
These will all be truthy. Should we change "not supported" to "" (like canPlayType)? |
Need to change the IDL to DOMString |
It should be an enum, not a DOMString, right? |
Yes, the basic idea, imo, is that falsy means API not supported, truthy means supported and then you can check the value. |
That seems like suboptimal ergonomics on the long term. I would rather have people check for |
@zcorpan, which three strings would you have? With two non-empty string, not both of them can mean supported, so I'm not quite seeing how to use this as a boolean even in the long run... |
Oh, wait, I guess you mean in the very distant future when one can assume that all browsers will support tokens so that conflating "no supported tokens" with "supported" wouldn't be a concern? |
Yeah. "No supported tokens" means n/a, e.g. for classList. No point in checking that value, but maybe nice to differentiate those two cases? |
Which long term are you thinking of? Note that one issue with the boolean setup that was raised is what happens if a list with no supported tokens changes to one with supported tokens. Suddenly you have no way to trust return values until everyone updates, and you can't even do the But also, what experience we have with the |
I was thinking of when you don't have to worry about browsers that return I don't mind having three states here, I just think it would be nice to be able to do a truthy check. I can buy that people will get comparisons wrong between empty string and undefined, but that is a temporary problem, right? |
How does that address the problem of supported token sets being added to something that doesn't have them? I guess we could have a falsy return value for "not supported" and two different truthy ones for "supported" and "no supported set", but that just means that code written to do the truthy check will break. If we think that at any point in the future things will transition from no supported set to having one, we really need to make it required to do an explicit tristate check for consumers.
Only if we think nothing else will ever transition from no supported set to supported set. |
I think we can assume that. All DOMTokenLists in all specs have been assessed and a supported set added where appropriate (or at least that was the intent). Future DOMTokenLists should consider this question immediately, not some time after they are introduced. It seems OK. |
OK I see what you are saying. I suppose we could make the classList case also be falsy, e.g. continue to return I would be fine with changing back classList to return |
I don't think so, so far HTML doesn't say anything about As for the enum values, they need to either not use spaces or use hyphens per https://w3ctag.github.io/design-principles/#casing-rules. |
I agree with @annevk that Are we all in agreement that a (truthy) tri-state is needed? Is there a preference with regard to strings vs. enums? |
Hold on. So in #103 (comment) it is pointed out that it's likely not going to be Web-compatible to reject invalid values for |
I was also a bit surprised to discover that in #111 (comment) I think we should change the return value only and not change the other behavior. A tri-state return value seems necessary, yes. Enums are string, so the question is only what the strings should be. |
Per IRC @zcorpan and I have a tentative new plan.
|
Looks good. I am in favor of C (which contradicts "Put to bed any worries about whether..."). |
So I went over the HTML spec and picked up all the relevant attributes. DOMTokenList:
DOMSettableTokenList:
As far as I can tell we can split them into:
Does that make sense? |
Yeah that makes sense. Note also #119 about simplifying the dual class setup to just a single class. |
Why? I think i prefer A because it leaves classList alone and makes it obvious how to feature-check for something moving from like-classList to like-relList, should that happen. |
@zcorpan - oops. Sorry. I must have been blind or too tired when I wrote it. I obviously meant A (which indeed contradicts that quote). Separate interfaces for an easy and accurate feature detection. |
@zcorpan - though, if A is chosen, the
The almighty |
The goal is not one-solution-fits-everything. Separate interfaces for |
I'm not so sure, it seems like a bit of overkill to introduce a new interface for this, is "Put to bed any worries about whether we'll in the future upgrade a DOMTokenList to have supported values by, once and for all, deciding on which DOMTokenLists receive this upgrade, and which don't" not enough? |
We cannot pretend to predict the future, so some kind of a feature detection for having supported tokens is needed. Either a new interface, or a |
This just seems wrong. No feature detection for having supported tokens is needed. We can easily decide which DOMTokenLists have supported tokens once and for all and never have to worry about "feature detection for having supported tokens". |
I prefer the |
I suppose that works. There could be concern that exposing an array opens up for misuse that is not possible with |
Damn. If code becomes dependable on the order... That would be really, really sad. :( This is a good incentive to change it every few months with a new great and shiney token. ;) |
This is the Web... :-( |
I don't think we should go with an array, since there's really no reason to. It's harder & more expensive to code to (have to iterate over it to find if an item is there), and would implicitly encourage dependence on implementation details such as order. |
|
Please stop insisting on |
Please, @domenic, stop making it look like a fact when it is not. Opinions diverge on the matter. |
Is plan A now to introduce |
Plans A-C are about basically deciding what |
OK. If it returns true when there are no supported tokens, then there will be an ugly but practical way to see if an object as has any supported tokens: (I don't think we should worry at all about the case where an attributes goes from having supported tokens to not having them.) |
We could also go with D) throw if |
This is an option. The only ugly thing about it is that try/catch patterns are generally less optimized in scripting engines, but I am not sure this should be considered here, as you can check it once and cache the result or something. |
D works for me. |
TypeError |
Closing as this PR is not the right way to go. Will PR what we discussed here shortly. |
This was originally discussed at whatwg/dom#114 (comment). PR: #395
As suggested by @bzbarsky:
Change the return value of add() to have three states: "supported", "not
supported" and "no supported tokens".
The "validation steps" algorithm return values also change accordingly.
/cc @foolip @zcorpan @annevk