Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1027 from PolymerElements/2.0-preview
Browse files Browse the repository at this point in the history
Migrate PSK to Polymer 2.0
  • Loading branch information
abdonrd committed Jul 26, 2017
2 parents 8e1030c + 1e0eeed commit e96167d
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 109 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
{
"extends": ["eslint:recommended", "google"],
"parserOptions": {
"ecmaVersion": 6
},
"env": {
"browser": true
},
"plugins": [
"html"
],
"rules": {
"brace-style": "off",
"new-cap": ["error", { "capIsNewExceptions": ["Polymer"] }],
"no-var": "off",
"new-cap": ["error", { "capIsNewExceptions": ["Polymer"] }]
"require-jsdoc": "off"
},
"globals": {
"Polymer": true
Expand Down
23 changes: 13 additions & 10 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
],
"license": "https://polymer.github.io/LICENSE.txt",
"dependencies": {
"app-layout": "PolymerElements/app-layout#^1.0.0",
"app-route": "PolymerElements/app-route#^1.0.0",
"iron-flex-layout": "PolymerElements/iron-flex-layout#^1.3.0",
"iron-iconset-svg": "PolymerElements/iron-iconset-svg#^1.1.0",
"iron-media-query": "PolymerElements/iron-media-query#^1.0.0",
"iron-pages": "PolymerElements/iron-pages#^1.0.0",
"iron-selector": "PolymerElements/iron-selector#^1.5.0",
"paper-icon-button": "PolymerElements/paper-icon-button#^1.1.0",
"polymer": "Polymer/polymer#^1.9.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0"
"app-layout": "PolymerElements/app-layout#^2.0.0",
"app-route": "PolymerElements/app-route#^2.0.0",
"iron-flex-layout": "PolymerElements/iron-flex-layout#^2.0.0",
"iron-iconset-svg": "PolymerElements/iron-iconset-svg#^2.0.0",
"iron-media-query": "PolymerElements/iron-media-query#^2.0.0",
"iron-pages": "PolymerElements/iron-pages#^2.0.0",
"iron-selector": "PolymerElements/iron-selector#^2.0.0",
"paper-icon-button": "PolymerElements/paper-icon-button#^2.0.0",
"polymer": "Polymer/polymer#^2.0.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^1.0.0"
},
"resolutions": {
"polymer": "^2.0.0"
},
"devDependencies": {
"web-component-tester": "Polymer/web-component-tester#^6.0.0"
Expand Down
50 changes: 8 additions & 42 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@
<meta name="msapplication-tap-highlight" content="no">

<script>
// Setup Polymer options
window.Polymer = {
dom: 'shadow',
lazyRegister: true,
};

/**
* [polymer-root-path]
*
Expand All @@ -78,42 +72,9 @@
* to indicate the path from which you'll be serving, including leading
* and trailing slashes (e.g., `/my-app/`).
*/
window.Polymer.rootPath = '/';

// Load webcomponentsjs polyfill if browser does not support native
// Web Components
(function() {
'use strict';

var onload = function() {
// For native Imports, manually fire WebComponentsReady so user code
// can use the same code path for native and polyfill'd imports.
if (!window.HTMLImports) {
document.dispatchEvent(
new CustomEvent('WebComponentsReady', {bubbles: true})
);
}
};

var webComponentsSupported = (
'registerElement' in document
&& 'import' in document.createElement('link')
&& 'content' in document.createElement('template')
);

if (!webComponentsSupported) {
var script = document.createElement('script');
script.async = true;
script.src =
'bower_components/webcomponentsjs/webcomponents-lite.min.js';
script.onload = onload;
document.head.appendChild(script);
} else {
onload();
}
})();

// Load pre-caching Service Worker
window.Polymer = {rootPath: '/'};

// Load and register pre-caching Service Worker
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('service-worker.js', {
Expand All @@ -123,8 +84,13 @@
}
</script>

<!-- Load webcomponents-loader.js to check and load any polyfills your browser needs -->
<script src="bower_components/webcomponentsjs/webcomponents-loader.js"></script>

<!-- Load your application shell -->
<link rel="import" href="src/my-app.html">

<!-- Add any global styles for body, document, etc. -->
<style>
body {
margin: 0;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"eslint-plugin-html": "^2.0.0"
},
"scripts": {
"lint": "npm run lint:javascript",
"lint": "npm run lint:javascript && polymer lint",
"lint:javascript": "eslint . --ext js,html --ignore-path .gitignore",
"test": "polymer test",
"test:integration": "polymer build # test that psk builds without error with the CLI"
Expand Down
4 changes: 2 additions & 2 deletions polymer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
],
"extraDependencies": [
"manifest.json",
"bower_components/webcomponentsjs/webcomponents-lite.min.js"
"bower_components/webcomponentsjs/*.js"
],
"lint": {
"rules": ["polymer-1"]
"rules": ["polymer-2"]
},
"builds": [
{
Expand Down
80 changes: 54 additions & 26 deletions src/my-app.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="../bower_components/app-layout/app-drawer/app-drawer.html">
<link rel="import" href="../bower_components/app-layout/app-drawer-layout/app-drawer-layout.html">
<link rel="import" href="../bower_components/app-layout/app-header/app-header.html">
Expand All @@ -22,6 +22,11 @@
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="my-icons.html">

<link rel="lazy-import" href="my-view1.html">
<link rel="lazy-import" href="my-view2.html">
<link rel="lazy-import" href="my-view3.html">
<link rel="lazy-import" href="my-view404.html">

<dom-module id="my-app">
<template>
<style>
Expand All @@ -32,10 +37,15 @@
display: block;
}

app-drawer-layout:not([narrow]) [drawer-toggle] {
display: none;
}

app-header {
color: #fff;
background-color: var(--app-primary-color);
}

app-header paper-icon-button {
--paper-icon-button-ink-color: white;
}
Expand Down Expand Up @@ -67,7 +77,7 @@

<app-drawer-layout fullbleed narrow="{{narrow}}">
<!-- Drawer content -->
<app-drawer id="drawer" swipe-open="[[narrow]]">
<app-drawer id="drawer" slot="drawer" swipe-open="[[narrow]]">
<app-toolbar>Menu</app-toolbar>
<iron-selector selected="[[page]]" attr-for-selected="name" class="drawer-list" role="navigation">
<a name="view1" href="[[rootPath]]view1">View One</a>
Expand All @@ -79,7 +89,7 @@
<!-- Main content -->
<app-header-layout has-scrolling-region>

<app-header condenses reveals effects="waterfall">
<app-header slot="header" condenses reveals effects="waterfall">
<app-toolbar>
<paper-icon-button icon="my-icons:menu" drawer-toggle></paper-icon-button>
<div main-title>My App</div>
Expand All @@ -101,38 +111,56 @@
</template>

<script>
Polymer({
is: 'my-app',

properties: {
page: {
type: String,
reflectToAttribute: true,
observer: '_pageChanged',
},
},

observers: [
'_routePageChanged(routeData.page)',
],

_routePageChanged: function(page) {
class MyApp extends Polymer.Element {
static get is() { return 'my-app'; }

static get properties() {
return {
page: {
type: String,
reflectToAttribute: true,
observer: '_pageChanged',
},
routeData: Object,
subroute: String,
// This shouldn't be neccessary, but the Analyzer isn't picking up
// Polymer.Element#rootPath
rootPath: String,
};
}

static get observers() {
return [
'_routePageChanged(routeData.page)',
];
}

_routePageChanged(page) {
// If no page was found in the route data, page will be an empty string.
// Deault to 'view1' in that case.
this.page = page || 'view1';

// Close a non-persistent drawer when the page & route are changed.
if (!this.$.drawer.persistent) {
this.$.drawer.close();
}
},
}

_pageChanged: function(page) {
_pageChanged(page) {
// Load page import on demand. Show 404 page if fails
var resolvedPageUrl = this.resolveUrl('my-' + page + '.html');
this.importHref(resolvedPageUrl, null, this._showPage404, true);
},
Polymer.importHref(
resolvedPageUrl,
null,
this._showPage404.bind(this),
true);
}

_showPage404: function() {
_showPage404() {
this.page = 'view404';
},
});
}
}

window.customElements.define(MyApp.is, MyApp);
</script>
</dom-module>
10 changes: 6 additions & 4 deletions src/my-view1.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="shared-styles.html">

<dom-module id="my-view1">
Expand All @@ -30,8 +30,10 @@ <h1>View One</h1>
</template>

<script>
Polymer({
is: 'my-view1',
});
class MyView1 extends Polymer.Element {
static get is() { return 'my-view1'; }
}

window.customElements.define(MyView1.is, MyView1);
</script>
</dom-module>
10 changes: 6 additions & 4 deletions src/my-view2.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="shared-styles.html">

<dom-module id="my-view2">
Expand All @@ -30,8 +30,10 @@ <h1>View Two</h1>
</template>

<script>
Polymer({
is: 'my-view2',
});
class MyView2 extends Polymer.Element {
static get is() { return 'my-view2'; }
}

window.customElements.define(MyView2.is, MyView2);
</script>
</dom-module>
10 changes: 6 additions & 4 deletions src/my-view3.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="shared-styles.html">

<dom-module id="my-view3">
Expand All @@ -30,8 +30,10 @@ <h1>View Three</h1>
</template>

<script>
Polymer({
is: 'my-view3',
});
class MyView3 extends Polymer.Element {
static get is() { return 'my-view3'; }
}

window.customElements.define(MyView3.is, MyView3);
</script>
</dom-module>
17 changes: 13 additions & 4 deletions src/my-view404.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/polymer/polymer-element.html">

<dom-module id="my-view404">
<template>
Expand All @@ -24,8 +24,17 @@
</template>

<script>
Polymer({
is: 'my-view404',
});
class MyView404 extends Polymer.Element {
static get is() { return 'my-view404'; }
static get properties() {
return {
// This shouldn't be neccessary, but the Analyzer isn't picking up
// Polymer.Element#rootPath
rootPath: String,
};
}
}

window.customElements.define(MyView404.is, MyView404);
</script>
</dom-module>
2 changes: 1 addition & 1 deletion src/shared-styles.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/polymer/polymer-element.html">

<!-- shared styles for all views -->
<dom-module id="shared-styles">
Expand Down
2 changes: 1 addition & 1 deletion sw-precache-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
staticFileGlobs: [
'index.html',
'manifest.json',
'bower_components/webcomponentsjs/webcomponents-lite.min.js',
'bower_components/webcomponentsjs/*',
],
navigateFallback: 'index.html',
};
Loading

0 comments on commit e96167d

Please sign in to comment.