-
Notifications
You must be signed in to change notification settings - Fork 378
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
CustomElementRegistry.define()
should return the new custom element
#927
Comments
Very nice idea, how did we miss this? @domenic What's the best place for this issue... Here? whatwg/html? |
Hmm this confuses me. |
I think the proposal is to return the second argument. I'm a bit hesitant to adding something like that because it closes the possibility of future extensions to |
Yes. The example code makes it clear the proposal is to return the constructor.
Don't those proposals suggest a new entrypoint for lazy definitions? But to be conservative, sure, maybe resolve #782 first and then do this. |
In general on the web platform this "chaining" style, where modifier functions return one of their arguments, is discouraged. If you have the argument already, having two ways to get it---the value you passed in, and the return value---just makes for unreadable code. In particular, the OP seems based on the misconception that customElements.get() returns something special. It does not. In the example given it just returns Text, which the code already has access to. |
@domenic you are right -- I misunderstood that Text would be the same returned value as the argument passed in. In any case, it would be nice if there was some kind of I can also call This is similar to the TC39 emplace proposal, which also lists some similar APIs in other languages: https://github.com/tc39/proposal-upsert |
Coming back to this -- I've changed my mind and think this should be closed since the error thrown from |
If calling
customElements.get()
returnsundefined
, and if we want to immediately set the custom element afterward, we would have to do something like:If
CustomElementRegistry.define()
returned the defined element, we could instead do:Or:
The text was updated successfully, but these errors were encountered: