Skip to content
This repository has been archived by the owner on Oct 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1 from webcomponents/initial
Browse files Browse the repository at this point in the history
Initial move from webcomponents.js
  • Loading branch information
justinfagnani authored Sep 8, 2016
2 parents 91d740e + 3f5abb7 commit e8b250b
Show file tree
Hide file tree
Showing 131 changed files with 15,826 additions and 35 deletions.
37 changes: 2 additions & 35 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,37 +1,4 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages
bower_components

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history
npm-debug.log*
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: node_js
sudo: required
dist: trusty
node_js: stable
addons:
sauce_connect: true
firefox: 48.0
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
before_script:
- export PATH=$PWD/node_modules/.bin:$PATH
script:
- npm run build
- xvfb-run wct
- if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then wct -s 'default'; fi
env:
global:
- secure: Fpp9LwJSGOdTrSIImQTlbzxozBsqe/2AJN5OfTXSe12FZxqzz50gevdxQcIlLypKaNyCtjb980DJbwdJR2cXUqaunLZAPWxrKa7ZPwamUxW+zVL7EHqy5zuvD+yJ+Vmk3ahs3WBTVyJ8T3XoaSfo9VumDIcKggWGJwgvM3blIMg=
- secure: Bj8MgzUVP0X8MLgK3d9eF48V7x0rPJyrN1IyguzKyJJVC8LV2XZXF+6o/M+zNsVMSsjhgXMkS3RRuaUShxO/OS6gHeG31FWcZqbXfZfgMMyH8a8zDls+r8m2lGEICaZo1OTXR0uiR/VNVt7n2xoBnTmjmRFwkaxAZk4yCjbXYzQ=
64 changes: 64 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Contributing

Want to contribute to webcomponents.js? Great!

We are more than happy to accept external contributions to the project in the form of [bug reports](../../issues) and pull requests.

## Contributor License Agreement

Before we can accept patches, there's a quick web form you need to fill out.

- If you're contributing as an individual (e.g. you own the intellectual property), fill out [this form](http://code.google.com/legal/individual-cla-v1.0.html).
- If you're contributing under a company, fill out [this form](http://code.google.com/legal/corporate-cla-v1.0.html) instead.

This CLA asserts that contributions are owned by you and that we can license all work under our [license](LICENSE).

Other projects require a similar agreement: jQuery, Firefox, Apache, Node, and many more.

[More about CLAs](https://www.google.com/search?q=Contributor%20License%20Agreement)

## Initial setup

1. Setup Gulp: `sudo npm install -g gulp`
1. Fork the project on github and pull down your copy.
> replace the {{ username }} with your username and {{ repository }} with the repository name
git clone [email protected]:{{ username }}/{{ repository }}.git

1. Test your change results in a working build.
> in the repo you've made changes to, try generating a build:
cd $REPO
npm install
gulp build

The builds will be placed into the `dist/` directory if all goes well.

1. Commit your code and make a pull request.

That's it for the one time setup. Now you're ready to make a change.

## Submitting a pull request

We iterate fast! To avoid potential merge conflicts, it's a good idea to pull from the main project before making a change and submitting a pull request. The easiest way to do this is setup a remote called `upstream` and do a pull before working on a change:

git remote add upstream git://github.com/polymer/webcomponentsjs.git

Then before making a change, do a pull from the upstream `master` branch:

git pull upstream master

To make life easier, add a "pull upstream" alias in your `.gitconfig`:

[alias]
pu = !"git fetch origin -v; git fetch upstream -v; git merge upstream/master"

That will pull in changes from your forked repo, the main (upstream) repo, and merge the two. Then it's just a matter of running `git pu` before a change and pushing to your repo:

git checkout master
git pu
# make change
git commit -a -m 'Awesome things.'
git push

Lastly, don't forget to submit the pull request.
24 changes: 24 additions & 0 deletions CustomElements.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions CustomElements.min.js.map

Large diffs are not rendered by default.

167 changes: 167 additions & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Custom Elements v1

## Status

The polyfill should be mostly feature complete now. It supports defining
custom elements, the custom element reactions, and upgrading existing elements. It integrates with native Shadow DOM v1, and native and polyfilled HTML Imports.

The implementation could use more tests, especially around ordering of
reactions. The source references old versions of the spec.

### To do

1. Implement Node#isConnected
2. Implement built-in element extension (is=)
3. Add reaction callback ordering tests
4. Reorganize tests to be closer to spec structure
5. Performance tests

## Building & Running Tests

1. Install web-component-tester

```bash
$ npm i -g web-component-tester
```

2. Checkout the webcomponentsjs v1 branch

```bash
$ git clone https://github.com/webcomponents/webcomponentsjs.git
$ cd webcomponentsjs
$ npm i
$ gulp build
```

3. Run tests

```bash
$ wct tests/CustomElements/v1/index.html -l chrome
```

4. Bower link to use in another project

```bash
$ bower link
$ cd {your project directory}
$ bower link webcomponentsjs
```

## Implementation approach and browser support

The polyfill leans heavily on MutationObservers to drive custom element creation and reactions. This means that the polyfill requires native or polyfilled MutationObservers. The polyfill also uses Map and Set, though those would be easy to polyfill or remove.

The implementation should work without additional polyfills in IE 11, Edge, Safari >6, Firefox, Chrome, Android Browser >4.4, and Opera (not Mini).

IE 10 should be supported with the Mutation Observer polyfill.

This branch does not pass the CI tests yet, but it passes locally in Chrome 52, Safari 9.1, Safari Technical Preview, and Firefox 47.

Because MutationObservers are used to create custom element instances and react to document structure and attribute changes, all reactions are asynchronous while in the specs, some are synchronous. This is by design, since some of the synchronous reactions are impossible to polyfill. We consider it more important that reactions have the same relative timing to each other as the spec, for example attributeChangedCallback happens after connectedCallback.

### Implementing the "Constructor-call Trick"

The HTMLElement constructor is now specified to return a different object than `this`, so that the parser and upgrades can call the constructor on elements that have already been allocated. JavaScript allows this, but some compilers, such as TypeScript and Closure currently don't.
The HTMLElement constructor is also specified to look up the tag name associated with a constructor by using `new.target`. `new.target` isn't available in ES5, is not polyfillable, but `this.constructor` behaves similarly for most ES5 class patterns, including the output of Babel, TypeScript and Closure, so the polyfill uses that to look up tag names.

`new.target` isn't even feature detectable, since it's a syntax error in ES5. Because of this, the polyfill can't check `new.target` first and fallback to `this.constructor`. This also means that ES5-style constructors can't conditionally make a "super" call to the HTMLElement constructor (with `Reflect.construct`) in non-ES6 environments to be compatible with native Custom Elements.

To allow for elements that work in both ES5 and ES6 environments, we provide a shim to be used in browsers that have native Custom Elements v1 support, that overrides the HTMLElement constructor and calls `Reflect.construct` with either the value of `new.target` or `this.constructor`. This shim can only be executed in ES6 environments that support `new.target`, and so should be conditionally loaded. The shim and the polyfill should not be loaded at the same time.

## Building

The Custom Elements V1 polyfill does not use the same module or build system as
the other webcomponentsjs polyfills, and its build is not integrated into the default build tasks yet.

To build run:

gulp CustomElementsV1

This creates a CustomElementsV1.min.js file in dist/

## Custom Elements in the DOM Spec

### 4.2.3 Mutation Algorithms

https://dom.spec.whatwg.org/#mutation-algorithms

* insert 6.5.2.1: call connectedCallback
* insert 6.5.2.2: upgrade
* remove 14: call disconnectedCallback
* remove 15.2: call disconnectedCallback

### 4.4 Node

https://dom.spec.whatwg.org/#concept-node-clone

* clone 2.1: performs create-element
* clone 2.2: append attributes

isConnected looks like it's Custom Elements related, but it's actually part of Shadow DOM. We might want to implement it for on non-native Shadow DOM environments, since we already watch for all connections and disconnections.

### 4.5 Document

https://dom.spec.whatwg.org/#interface-document

* createElement and createElementNS take ElementCreationOptions

https://dom.spec.whatwg.org/#dom-document-createelement

* createElement 3, 4, 5, 7
* createElementNS 2, 3, 4, 5

### 4.9 Element

https://dom.spec.whatwg.org/#concept-element-custom-element-state

https://dom.spec.whatwg.org/#concept-create-element

* create an element 2, 3, 4, 5, 6

https://dom.spec.whatwg.org/#concept-element-attributes-change

* change an attribute 2

https://dom.spec.whatwg.org/#concept-element-attributes-append

* append an attribute 2

https://dom.spec.whatwg.org/#concept-element-attributes-remove

* remove an attribute 2

https://dom.spec.whatwg.org/#concept-element-attributes-replace

* replace an attribute 2

https://dom.spec.whatwg.org/#dom-element-attachshadow

* attachShadow 2 (nothing to implement)

## Custom Elements in the HTML Spec


### 3.2.3 HTML element constructors

https://html.spec.whatwg.org/multipage/dom.html#html-element-constructors

* HTML element constructors 1-9

### 4.13 Custom Elements

https://html.spec.whatwg.org/multipage/scripting.html#custom-elements

https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-element-name

https://html.spec.whatwg.org/multipage/scripting.html#customelementsregistry

### 7.3 Window

https://html.spec.whatwg.org/multipage/browsers.html#window

* Window#customElements

https://html.spec.whatwg.org/multipage/syntax.html#create-an-element-for-the-token

* create an element for a token 3, 4, 5, 6, 7, 8, 9
19 changes: 19 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# License

Everything in this repo is BSD style license unless otherwise specified.

Copyright (c) 2015 The Polymer Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading

0 comments on commit e8b250b

Please sign in to comment.