Skip to content
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

Incomplete iterable DOM changes for discussion #249

Merged
merged 2 commits into from
Nov 4, 2016

Conversation

loganfsmyth
Copy link
Contributor

Posting for discussion given babel/babel#4616. Not a complete fix because I wanted to get your thoughts before going further.

As far as I can tell, and given the behavior in Chrome and FF, these are supposed to be iterable because of the behavior documented in https://heycam.github.io/webidl/#es-iterators for IDL. It says any integer-indexed class should be considered iterable automatically, but only those explicitly marked Iterable in the IDL should get keys, values and entries.

Given that, the current behavior of of MediaList, StyleSheetList, and CSSRuleList aren't quite right since they should not have an .keys, .values and .entries. Only NodeList and DOMTokenList are explicitly Iterable<> in the DOM spec.

I've pulled in a list of DOM classes that are currently iterable in Chrome/FF and merged them together with a bit of cleanup. This covers HTMLCollection and NamedNodeMap, which are probably the main important ones people are likely to want to use.

@zloirock
Copy link
Owner

zloirock commented Oct 8, 2016

Thanks! Sorry, I missed your comment in this discussion. If it should be added by Web IDL - we should add it. I'll check docs when I'll have time. Removing methods is a breaking change, but anyway, I want to work on a major release.

@loganfsmyth
Copy link
Contributor Author

Yeah, wasn't sure what your thoughts were on that .keys etc change. Would you be open to landing a change like this if we just leave the existing ones as true for now for compatibility with existing code? I'm hesitant to wait on a 3.x release since we'd have to decide whether we could adopt it for Babel 6 anyway.

@zloirock
Copy link
Owner

Would you be open to landing a change like this if we just leave the existing ones as true for now for compatibility with existing code?

Yep.

I'm hesitant to wait on a 3.x release since we'd have to decide whether we could adopt it for Babel 6 anyway.

Most likely it would be problematic - too many breaking changes in proposals and I wanted to add some breaking changes to API. So most likely it's for babel@7.

@loganfsmyth
Copy link
Contributor Author

@zloirock Could you give me some pointers on the filesystem structure? I'm confused about why there are three files

  • modules/web.dom.iterable
  • modules/library/web.dom.iterable
  • library/modules/web.dom.iterable

The last two add NAME to Iterators but don't mutate the proto since it is a global. What effect does that do in this case? Do I need to expand those lists with the larger set of names?

@zloirock
Copy link
Owner

zloirock commented Oct 11, 2016

modules/web.dom.iterable

It's for global polyfill.

modules/library/web.dom.iterable

It's for the version without global namespace pollution if it's deferred from the global version.

library/modules/web.dom.iterable

It's final library version generated as copying modules and, after, modules/library to one folder at the build time. Ugly, but it works :-)

So you should change the first 2 and add tests if it's not hard.

@loganfsmyth
Copy link
Contributor Author

Ah okay, library/modules/web.dom.iterable was the main one that confused me, didn't realize it got copied.

For the logic in modules/library/web.dom.iterable, how does it affect iterability of the globals? Is there internal logic somewhere else?

@zloirock
Copy link
Owner

zloirock commented Oct 11, 2016

how does it affect iterability of the globals?

It uses Object.prototype.toString for getting an internal class name and uses matched iterators.

@zloirock
Copy link
Owner

...and looks like that in one case I forgot to add one additional check for toString value, so we have some minor and hidden, but pollution in old engines. I should review my old code one more time :-)

@loganfsmyth
Copy link
Contributor Author

@zloirock I assume I'm doing something dumb, mind taking a look and telling me why these tests are failing now?

@loganfsmyth
Copy link
Contributor Author

@zloirock Thoughts?

@zloirock
Copy link
Owner

zloirock commented Nov 3, 2016

@loganfsmyth sorry, I had some problems with time and I missed your message. I'll check it in the evening.

@loganfsmyth
Copy link
Contributor Author

No rush, I figured it had gotten lost.

TextTrackCueList: false,
TextTrackList: false,
TouchList: false
};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In library version, we don't need keys / values / entries methods, so we can replace it with an array and get rid of _object-keys dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was on the fence, I figured keeping the two implementations similar was better but totally your call.

@zloirock
Copy link
Owner

zloirock commented Nov 4, 2016

I assume I'm doing something dumb, mind taking a look and telling me why these tests are failing now?

Looks like the problem that npm test does not contain copy task. I missed it because I usually run build task before commits. Need to add it.

@zloirock zloirock merged commit af011af into zloirock:master Nov 4, 2016
zloirock added a commit that referenced this pull request Nov 4, 2016
zloirock added a commit that referenced this pull request Nov 4, 2016
@loganfsmyth loganfsmyth deleted the iterable-dom-types branch November 4, 2016 17:24
facebook-github-bot pushed a commit to facebook/flow that referenced this pull request Jan 6, 2017
Summary:
These DOM properties are definitely nullable, though in the average case they probably exist. I assume it's best for the type definitions to cover all the possibilities.

For the iterability, Chome added these in a few releases ago and the next release of core-js should include polyfill logic for them. More info in zloirock/core-js#249
Closes #3127

Differential Revision: D4388268

Pulled By: gabelevi

fbshipit-source-id: 282238b38f82fb71db87f88eb7f9583c20286724
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants