Giter VIP home page Giter VIP logo

old-docs-site's Introduction

Polymer

Build Status Published on npm Published on webcomponents.org

โ„น๏ธ Note: This is the current stable version of the Polymer library. At Google I/O 2018 we announced a new Web Component base class, LitElement, as a successor to the PolymerElement base class in this library.

If you're starting a new project, we recommend that you consider using LitElement instead.

If you have a project you've built with an earlier version of the Polymer library, we recommend that you migrate to 3.0 for best compatibility with the JavaScript ecosystem. Thanks to the interoperability of Web Components, elements built with Polymer 3.0 and LitElement can be mixed and matched in the same app, so once you have updated your project to Polymer 3.0, you can migrate to LitElement incrementally, one element at a time. See our blog post on the Polymer Project roadmap for more information.

Polymer lets you build encapsulated, reusable Web Components that work just like standard HTML elements, to use in building web applications. Using a Web Component built with Polymer is as simple as importing its definition then using it like any other HTML element:

<!-- Import a component -->
<script src="https://unpkg.com/@polymer/paper-checkbox@next/paper-checkbox.js?module" type="module" ></script>

<!-- Use it like any other HTML element -->
<paper-checkbox>Web Components!</paper-checkbox>

Web Components are now implemented natively on Safari and Chrome (~70% of installed browsers), and run well on Firefox, Edge, and IE11 using polyfills. Read more below.

Getting started

  • The easiest way to try out Polymer is to use one of these online tools:

  • You can also save this HTML file to a local file and run it in any browser that supports JavaScript Modules.

  • When you're ready to use Polymer in a project, install it via npm. To run the project in the browser, a module-compatible toolchain is required. We recommend installing the Polymer CLI to and using its development server as follows.

    1. Add Polymer to your project:

      npm i @polymer/polymer

    2. Create an element by extending PolymerElement and calling customElements.define with your class (see the examples below).

    3. Install the Polymer CLI:

      npm i -g polymer-cli

    4. Run the development server and open a browser pointing to its URL:

      polymer serve --npm

    Polymer 3.0 is published on npm using JavaScript Modules. This means it can take advantage of the standard native JavaScript module loader available in all current major browsers.

    However, since Polymer uses npm conventions to reference dependencies by name, a light transform to rewrite specifiers to URLs is required to run in the browser. The polymer-cli's development server polymer serve, as well as polymer build (for building an optimized app for deployment) automatically handles this transform.

    Tools like webpack and Rollup can also be used to serve and/or bundle Polymer elements.

Minimal Example

  1. Create a class that extends PolymerElement.
  2. Implement a static properties getter that describes the element's public property/attribute API (these automatically become observed attributes).
  3. Then implement a template getter that returns an HTMLTemplateElement describing the element's rendering, including encapsulated styling and any property bindings.
  <script src="node_modules/@webcomponents/webcomponents-loader.js"></script>
  <script type="module">
    import {PolymerElement, html} from '@polymer/polymer';

    class MyElement extends PolymerElement {
      static get properties() { return { mood: String }}
      static get template() {
        return html`
          <style> .mood { color: green; } </style>
          Web Components are <span class="mood">[[mood]]</span>!
        `;
      }
    }

    customElements.define('my-element', MyElement);
  </script>

  <my-element mood="happy"></my-element>

Overview

Web components are an incredibly powerful new set of primitives baked into the web platform, and open up a whole new world of possibility when it comes to componentizing front-end code and easily creating powerful, immersive, app-like experiences on the web.

Polymer is a lightweight library built on top of the web standards-based Web Components APIs, and makes it easier to build your very own custom HTML elements. Creating reusable custom elements - and using elements built by others - can make building complex web applications easier and more efficient.

By being based on the Web Components APIs built in the browser (or polyfilled where needed), elements built with Polymer are:

  • Built from the platform up
  • Self-contained
  • Re-usable
  • Interoperable across frameworks

Among many ways to leverage custom elements, they can be particularly useful for building reusable UI components. Instead of continually re-building a specific navigation bar or button in different frameworks and for different projects, you can define this element once using Polymer, and then reuse it throughout your project or in any future project.

Polymer provides a declarative syntax to easily create your own custom elements, using all standard web technologies - define the structure of the element with HTML, style it with CSS, and add interactions to the element with JavaScript.

Polymer also provides optional two-way data-binding, meaning:

  1. When properties in the model for an element get updated, the element can update itself in response.
  2. When the element is updated internally, the changes can be propagated back to the model.

Polymer is designed to be flexible, lightweight, and close to the web platform - the library doesn't invent complex new abstractions and magic, but uses the best features of the web platform in straightforward ways to simply sugar the creation of custom elements.

About Polymer 3.0

Polymer 3.0 is now released to stable, and introduces a major change to how Polymer is distributed: from HTML Imports on Bower, to JS modules on npm. Otherwise, the API is almost entirely backward compatible with Polymer 2.0 (the only changes are removing APIs related to HTML Imports like importHref, and converting Polymer's API to be module-based rather than globals-based).

Migrating to Polymer 3.0 by hand is mostly mechanical:

  • Components should be defined in JS modules instead of in HTML
  • Templates should be encoded in JS modules using a static get template() getter on PolymerElement subclasses using the html tagged template literal function (which parses HTMLTemplateElements out of strings in JS) rather than using <template> elements in a <dom-module>
  • All dependencies should be imported JS module imports rather than HTML Imports.

However, the polymer-modulizer tool automates the vast majority of this migration work. Please see details on that repo for automated conversion of Polymer 2.0 apps and elements to Polymer 3.0.

๐Ÿ‘€ Looking for Polymer v2.x? Please see the v2 branch.

๐Ÿ‘€ Looking for Polymer v1.x? Please see the v1 branch.

Contributing

The Polymer team loves contributions from the community! Take a look at our contributing guide for more information on how to contribute. Please file issues on the Polymer issue tracker following the issue template and contributing guide issues.

Communicating with the Polymer team

Beyond GitHub, we try to have a variety of different lines of communication available:

License

The Polymer library uses a BSD-like license that is available here

old-docs-site's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

old-docs-site's Issues

Compatibility matrix

Which features are implemented in which browsers natively, with shim, with polyfill, or unsupported.

Improve description of our layered architecture

The architecture diagram is very information rich, but it's hard to digest at first.

We should consider having a page that walks people through our architecture, introducing each layer one a time like we did in the I/O session. That would allow us to call out details like 3rd party frameworks/component sets interoperating.

Document ways to do message passing & Events between components

  • this.fire()
  • Using their public api
  • data binding attributes on the same property

* Use MDV data binding w/ published properties: like a bus*

(the approach TodoMVC uses)

<element name="my-app">
<template>
  <td-model items="{{items}}"></td-model>
  <polymer-localstorage value="{{items}}"></polymer-localstorage>
  <div>{{items}}</div>
</template>
</element>

This is great if you're in a Polymer element and want to "link" elements together via a binded property. When <td-model> updates its internal array, other elements that bind to its published "items" property see those changes. Essentially, you've put "items" on a bus, internal to <my-app>.

*_Use _Changedwatchers`

Instead, say <polymer-localstorage> didn't publish "value" and we didn't have that attribute to bind to. In this case, you could setup a *Change watcher.

<template>
  <td-model items="{{items}}"></td-model>
  <polymer-localstorage id="storage"></polymer-localstorage>
</template>
<script>
  Polymer.register(this, {
    itemsChanged: function() {
      // TODO: tell this.$.storage something has changed.
    }
  });
</script>

Fire custom events

Custom events bubble up. You can use an event delegation
scheme by declaring a on-* handler on your outer most <element>.
I call this method as the air traffic controller.

<element name="my-element">
  <template>Hello</template>
  <script>
    Polymer.register(this, { ready: function() { this.asyncFire('myevent'); } });
  </script>
</element>

<element name="my-app" on-myevent="doMyEvent">
  <template>
    <my-element></my-element>
  </template>
  <script>
    Polymer.register(this, {
      doMyEvent: function(e, details, sender) {
        console.log(e.type, details, sender);
        // TODO: act on this.
      }
    });
  </script>
</element>

http://jsbin.com/ekahug/4/edit

Find way not to duplicate same components

We currently have sample components in /samples/components/ which are duplicated in _includes/samples/ for including into the docs. Unfortunately, Jekyll only allows you to include partials that are under _includes.

The ones in /samples/components/ are used for live samples.

One way around this would be to great a samples repo and submodule it into _includes
as well as the main folder.

Write "Lessons learned from developing Polymer"

Why it's implemented this way; what we learned from exploring the technologies. Footsteps for other toolkits to follow in, and beginning place for web component compatibility to grow from, etc.

Spec vs. toolkit features

The intros are great. It'd be helpful (for me at least) to know what features being explained are part of the standards-track process and which are conveniences provided by the toolkit. For instance, I suspect that the "$" property might be toolkitchen specific, but I don't know and the intro doesn't help me find out.

Can `platform.js` be async or defer?

The examples show it being loaded synchronously, which might be OK, but it doesn't clarify what can and can't be loaded async. See:

http://toolkitchen.github.com/docs/getting-started.html

Document debug runtime flag

The default is to load a minified version of platform and to include Shadow DOM polyfill support only where needed. The defaults can be altered using run-time flags.

The matrix is something like this:

[flags] loads [target]

[] loads [platform.min.js]
[debug] loads [platform.debug.js]
[shadow=polyfill] loads [platform.poly.min.js]
[shadow=polyfill, debug] loads [platform.debug.js] loads [ShadowDOM Polyfill]

Note that the shadow flag defaults to 'polyfill' on platforms where native Shadow DOM is not detected.

Flags can be specified on the main URL or on the script tag which loads platform.js.

Examples:

http://localhost/someapp.html?debug&shadow=polyfill

or

<script src="../platform/platform.js" debug shadow="polyfill">

Note that the non-debug (minified) versions of the platform must be built via the (default) grunt task if source is modified. There are minified versions of platform.js (platform.min.js and platform.poly.min.js) checked in to the repository now that we will attempt to keep current. Ultimately some post-commit hook to keep them fresh would be great.

workbench is for hammering on things, it's not actually examples

This is subtle, but we decided early that "workbench" was literally for files and tests we need while working on components. It's a mistake to conflate that with "examples", since the latter would have different requirements for readability and so on.

There really is no "examples". We need something cool for that. =P

Add FAQ to the, er, well, FAQ

From the mailing list:

What differences there is between Polymer and Angular, and respect to Dart's Web UI ?

Why does Google is developing three different technologies for the web front-end instead of to create one only killer technology?

Document @polyfill

The ShadowDOM polyfill does not cover ShadowDOM css scoping behavior. Toolkit has a partial shim for this behavior.

  1. @host rules are converted to rules prefixed with the element's tag name. For example this rule inside an x-foo

    @host {

    • { ...
      }
      }

becomes:

x-foo { ...
}
  1. Selectors in shadowRoot style elements are prepended with the element name and a space, creating a descendent selector. This makes sure the styling does not leak outside the shadowRoot. For example, inside an x-foo, this rule:

    div { ... }

becomes:

x-foo div { ... }
  1. For other complex styling, we've included the @polyfill directive which can be placed inside a css comment. The seletor next to @polyfill replaces the next selector in the style element. For example, a distributed rule can be polyfilled manually with careful use of selectors:

    /* @polyfill .container .bar */
    content::-webkit-distributed(.bar) { ... }

Under native ShadowDOM polyfill, the rule is as written. Under the polyfill, it becomes:

.container .bar { ... }

Document existence of toolkit-ui repo

The elements in toolkit have now been separated into the toolkit-ui repository.

The docs should mention that toolkit elements are in the toolkit-ui repo.

Typo in toolkit-kernel-explainer.html

I wanted to do a pull request but I don't see how you generate the documents.

Under "Public properties"

this.component({
  clickColor: 'orange',
  clickHandler: function() {
    this.node.style.backgroundColor = this.clickColor;
  },
  publish: {
    this.clickColor = 'red',

  }
});

should be

this.component({
  clickColor: 'orange',
  clickHandler: function() {
    this.node.style.backgroundColor = this.clickColor;
  },
  publish: {
    clickColor: 'red'
  }
});

publish is an object literal, not a block. I think you might want to update the text too since you refer to it as a block in places.

Introduction graphic is a bit misleading

I don't understand the vertical (apparently stacked) relationship in the intro diagram. Many of the stuff at the highest level would exist at many "low" levels in an app. Likewise, why is the toolkit in the middle? Between the platform and Toolkitchen, quiet a lot is still being left to the user, and those things aren't called out clearly in the graphic here:

http://toolkitchen.github.com/docs/images/architecture.png

It'd be great if there were color coding for what you'd need to bring/build in your own app. Addiitionally, we should call out BYO features of any app such as a data model, storage/synchronization strategy, UI layout, and of course app features ;-)

Create glossary of terms

Define key terms of this emerging platform (web components, shadow DOM, custom elements, MDV, etc.)

Errors in getting-started.html (reported on tookitchen group)

  • g-component link tag uses toolkit/src/g-component which is located in toolkit/components
  • Many examples lack the g-component link tag entirely (tk-binding-to-elements, tk-element-ready, tk-node-finding)
  • There are several cases of {{owner}} missing (tk-element-property-public, tk-element-public-access, tk-element-public-access)
  • {{color}} missing from tk-node-finding

Re: "applications can be both extremely simple and arbitrarily complicated."

This is nitpicky, so feel free to ignore.

The original text I think used "simultaneously" instead of "both". The intention is to say that one application can be at once complex (in the gestalt) and simple (when viewed as a collection of components). Using "both" it reads IMO that toolkit is suitable for both complicated applications and simple applications, which is not the same thing at all.

Btw, "extremely simple" is hyperbole, but I couldn't think of better phrasing there.

Btw #2: good job on these documents in general.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.