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

Commit

Permalink
Merge pull request #112 from PolymerElements/2.0-preview
Browse files Browse the repository at this point in the history
2.0 hybrid implementation
  • Loading branch information
e111077 authored Jul 20, 2017
2 parents a8e6592 + b95038e commit a238008
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 58 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bower_components
bower_components*
bower-*.json
39 changes: 13 additions & 26 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
language: node_js
sudo: required
matrix:
include:
- node_js: stable
script: xvfb-run wct
addons:
firefox: latest
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
- node_js: node
script:
- |
if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then
wct -s 'default'
fi
before_script:
- npm install -g bower polylint web-component-tester
- bower install
- polylint
node_js: '6'
node_js: stable
addons:
firefox: latest
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
dist: trusty
before_script:
- npm install -g polymer-cli
- polymer install --variants
script:
- xvfb-run polymer test
- >-
if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then polymer test -s 'default';
fi
env:
global:
- secure: >-
BmIBRLipjyXtAB13z4QjER1s70X4uRwGkn2LiNMlZUgU8/4ZhbHefj728hLnk0HkoSVYIInLmz2gx2BS4vT2bnlQYLyVTO6KUA6vbIU8XQGqOTJeDASlfHR8qr+YAxlJ3vovwkzldAdzhS90cqAdmNOZxfMIjHTtLoqJX2YvkhHKT/joJvAYQFBSqkMZMI7mZf3PN70RNqMDz3S4I6P1ETpgL0JuuG54/hFjAVN7F/6pdYeI/G5gfixrfk8Na+Ys5PSnZB8yjol5fX6395gxNOjUYIH2kP44ewGNKJEy4ZIQmguNjlq734HGqfTvtpzoCTIuuTvgAwo+0aJyK8YSBLKUXiWDJdqfNLPbYKJ1QYOkqQ+WcsKYFTPJF43C2mmZiuyi7Oks2ovxYFg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k78eYqFBQbVqoMuteBlVpbBrwf6HtQ3kmqwpRHruSfaZSV68k0D4cjKvZAKxGBWKdbysuDL6GHaLbO7dANuwyW7VW8FhYsWoppfY70vYsmtT/YAxOu0XXMeyzQJPNOoYhV/JMFR+nV0+x1FTxfc8+BWdgMLkWt8LZUk6wMY1LG3W0t+Muc460QhiIT1WL5u6WkVw=
dist: trusty
sudo: required
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
⚠️ This Element is now deprecated in favor of [workbox](https://github.com/GoogleChrome/workbox) and [sw-toolbox](https://github.com/GoogleChrome/sw-toolbox) ⚠️

# Platinum Service Worker Elements
A set of Polymer elements that simplify service worker registration and caching, powered by the
[`sw-toolbox` library](https://github.com/googlechrome/sw-toolbox).
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/sw-toolbox-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if (cacheId) {
global.toolbox.options.cacheName = cacheId + '$$$' + global.registration.scope;
}

if (global.params.has('defaultCacheStrategy')) {
var strategy = global.params.get('defaultCacheStrategy');
global.toolbox.router.default = global.toolbox[strategy] || global[strategy];
Expand All @@ -43,7 +43,7 @@
}

global.toolbox.precache(precachePromise);

if (global.params.has('route')) {
var setsOfRouteParams = global.params.get('route');
while (setsOfRouteParams.length > 0) {
Expand Down
36 changes: 29 additions & 7 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "platinum-sw",
"private": true,
"version": "1.2.4",
"version": "2.0.0",
"license": "http://polymer.github.io/LICENSE.txt",
"authors": [
"The Polymer Authors"
Expand All @@ -23,13 +23,35 @@
"bower_components"
],
"dependencies": {
"polymer": "Polymer/polymer#^1.5.0",
"sw-toolbox": "^3.1.1"
"polymer": "Polymer/polymer#1.9 - 2",
"sw-toolbox": "^3.6.1"
},
"devDependencies": {
"iron-component-page": "PolymerElements/iron-component-page#^1.0.2",
"marked-element": "PolymerElements/marked-element#^1.0.0",
"web-component-tester": "^4.0.0",
"fetch": "^0.9.0"
"fetch": "^0.9.0",
"iron-component-page": "PolymerElements/iron-component-page#1 - 2",
"marked-element": "PolymerElements/marked-element#1 - 2",
"web-component-tester": "Polymer/web-component-tester#^6.0.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^1.0.0"
},
"variants": {
"1.x": {
"dependencies": {
"polymer": "Polymer/polymer#^1.5.0",
"sw-toolbox": "^3.6.1"
},
"devDependencies": {
"fetch": "^0.9.0",
"iron-component-page": "PolymerElements/iron-component-page#^1.0.2",
"marked-element": "PolymerElements/marked-element#^1.0.0",
"web-component-tester": "^4.0.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0"
},
"resolutions": {
"webcomponentsjs": "^0.7"
}
}
},
"resolutions": {
"webcomponentsjs": "^1.0.0"
}
}
33 changes: 28 additions & 5 deletions platinum-sw-register.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
// Fallback to './' as a default, though current browsers that don't support
// document.currentScript also don't support service workers.
value: document._currentScript ? document._currentScript.baseURI :
(document.currentScript ? document.currentScript.baseURI : './')
(HTMLImports.importForElement ? HTMLImports.importForElement(document.currentScript).baseURI :
(document.currentScript ? document.currentScript.baseURI : './'))
},

/**
Expand Down Expand Up @@ -251,9 +252,6 @@
this._constructServiceWorkerUrl().then(function(serviceWorkerUrl) {
this._registerServiceWorker(serviceWorkerUrl);
}.bind(this));
} else {
this._setState('unsupported');
this.fire('service-worker-error', 'Service workers are not available in the current browser.');
}
},

Expand Down Expand Up @@ -376,8 +374,33 @@
},

attached: function() {
var isSupported = 'serviceWorker' in navigator;

if (!isSupported) {
this._setState('unsupported');
return;
}

if (this.autoRegister) {
this.async(this.register);
/**
* Register requires all elements in the light dom to be upgraded. This
* behavior was expected in Polymer 1 but no longer in Polymer 2.
* Elements that are imported synchronously should be upgraded after
* the document's readyState is interactive and a
* requestAnimationFrame.
*/
if (document.readyState !== 'complete' &&
document.readyState !== 'interactive') {

document.onreadystatechange = function() {
if (document.readyState === 'interactive') {
window.requestAnimationFrame(this.register.bind(this));
}
}.bind(this);

} else {
window.requestAnimationFrame(this.register.bind(this));
}
}
}
});
Expand Down
14 changes: 7 additions & 7 deletions service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

(function(global) {
var VERSION = '1.0';

function deserializeUrlParams(queryString) {
return new Map(queryString.split('&').map(function(keyValuePair) {
var splits = keyValuePair.split('=');
Expand All @@ -19,18 +19,18 @@
if (value.indexOf(',') >= 0) {
value = value.split(',');
}

return [key, value];
}));
}

global.params = deserializeUrlParams(location.search.substring(1));

if (global.params.get('version') !== VERSION) {
throw 'The registered script is version ' + VERSION +
' and cannot be used with <platinum-sw-register> version ' + global.params.get('version');
}

if (global.params.has('importscript')) {
var scripts = global.params.get('importscript');
if (Array.isArray(scripts)) {
Expand All @@ -39,13 +39,13 @@
importScripts(scripts);
}
}

if (global.params.get('skipWaiting') === 'true' && global.skipWaiting) {
global.addEventListener('install', function(e) {
e.waitUntil(global.skipWaiting());
});
}

if (global.params.get('clientsClaim') === 'true' && global.clients && global.clients.claim) {
global.addEventListener('activate', function(e) {
e.waitUntil(global.clients.claim());
Expand Down
16 changes: 8 additions & 8 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@
// Keep each test suite in its own directory so that it gets a SW registered with a
// limited scope, just in case the browser environment is not cleared in between each
// test suite.
'platinum-sw-register/index.html',
'platinum-sw-cache/index.html',
'platinum-sw-import-script/index.html',
'platinum-sw-fetch/index.html',
'platinum-sw-register/index.html?dom=shadow',
'platinum-sw-cache/index.html?dom=shadow',
'platinum-sw-import-script/index.html?dom=shadow',
'platinum-sw-fetch/index.html?dom=shadow'
'platinum-sw-fetch/index.html?dom=shadow',
'platinum-sw-register/index.html?wc-shadowdom=true&wc-ce=true',
'platinum-sw-cache/index.html?wc-shadowdom=true&wc-ce=true',
'platinum-sw-import-script/index.html?wc-shadowdom=true&wc-ce=true',
'platinum-sw-fetch/index.html?wc-shadowdom=true&wc-ce=true'
]);
} else {
WCT.loadSuites([
'platinum-sw-unsupported.html',
'platinum-sw-unsupported.html?dom=shadow'
'platinum-sw-unsupported.html?dom=shadow',
'platinum-sw-unsupported.html?wc-shadowdom=true&wc-ce=true'
]);
}
</script>


</body></html>
2 changes: 1 addition & 1 deletion test/platinum-sw-import-script/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<script>
suite('Importing Service Worker Scripts', function() {
test('message handler is registered via imported script', function(done) {
return window._controlledPromise.then(function(registration) {
window._controlledPromise.then(function(registration) {
var message = 'hello';
var messageChannel = new MessageChannel();
messageChannel.port1.onmessage = function(event) {
Expand Down
2 changes: 1 addition & 1 deletion test/platinum-sw-unsupported.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<platinum-sw-register auto-register></platinum-sw-register>

<script>
document.addEventListener('WebComponentsReady', function() {
window.addEventListener('WebComponentsReady', function() {
var sw = document.querySelector('platinum-sw-register');
suite('Unsupported', function() {
test('state is properly set', function() {
Expand Down

0 comments on commit a238008

Please sign in to comment.