Skip to content

Commit

Permalink
Merge pull request #26 from gregoranders/development
Browse files Browse the repository at this point in the history
Initial service worker
  • Loading branch information
gregoranders authored Jun 12, 2020
2 parents aae9866 + 99b9aa7 commit 94ed9d9
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* TypeScript
* React + React-Router + Recoil
* SCSS
* ServiceWorker with PWA
* Jest Snapshot/Unit Tests with Code Coverage (enzyme)
* Jest + Puppeteer (screenshots from submodule) E2E Tests
* Storybook (publish via CI into submodule)
Expand Down
1 change: 1 addition & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
| Version | Supported |
| ------- | ------------------ |
| 0.0.7 | :white_check_mark: |
| 0.0.6 | :white_check_mark: |
| 0.0.5 | :white_check_mark: |
| 0.0.4 | :white_check_mark: |
Expand Down
3 changes: 2 additions & 1 deletion docs/Intro.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Meta } from '@storybook/addon-docs/blocks';

<Meta title="Docs|Intro" />

# ts-react-playground - [TypeScript](http://www.typescriptlang.org/) [React](https://reactjs.org/) Playground v0.0.6
# ts-react-playground - [TypeScript](http://www.typescriptlang.org/) [React](https://reactjs.org/) Playground v0.0.7

[![Dependency Status][daviddm-image]][daviddm-url]
[![License][license-image]][license-url]
Expand All @@ -16,6 +16,7 @@ import { Meta } from '@storybook/addon-docs/blocks';
* TypeScript
* React + React-Router + Recoil
* SCSS
* ServiceWorker with PWA
* Jest Snapshot/Unit Tests with Code Coverage (enzyme)
* Jest + Puppeteer (screenshots from submodule) E2E Tests
* Storybook (publish via CI into submodule)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "ts-react-playground",
"version": "0.0.6",
"version": "0.0.7",
"description": "TypeScript React Playground",
"scripts": {
"start": "webpack-dev-server --open --progress --config webpack.config.js",
"clear": "npm run prebuild && rimraf ./node_modules ./dist ./coverage ./coverage-e2e ./package-lock.json .jest-test-results.json junit.xml",
"prebuild": "npm run prebuild:webpack",
"prebuild": "npm run prebuild:webpack && npm run prebuild:esm",
"build": "npm run build:webpack",
"prebuild:esm": "npm run prevendor && npm run prescript && npm run preserviceWorker && npm run prescss && npm run prefavicon",
"build:esm": "npm run vendor && npm run script && npm run scss && npm run favicon && npm run serviceWorker",
Expand Down
13 changes: 9 additions & 4 deletions src/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,28 @@ namespace CustomServiceWorkerNS {

private onInstall(event: ExtendableEvent) {
event.waitUntil(
new Promise<void>((resolve) => {
resolve(this.cache.register(this.basename));
new Promise<void>(async (resolve) => {
await this.cache.register(this.basename);
resolve(this.service.skipWaiting());
}),
);
}

private onActivate(event: ExtendableEvent) {
CustomServiceWorkerNS.log('onActivate');
event.waitUntil(this.service.clients.claim());
event.waitUntil(
new Promise<void>(async (resolve) => {
resolve(this.service.clients.claim());
}),
);
}

private onFetch(event: FetchEvent) {
this.cache.fetch(event);
}
}

export const log = (...args: unknown[]) => {
export const log = (...args: unknown[]): void => {
const styles = [`background-color: #008`];
console.log(...[`%cServiceWorker ${CustomServiceWorkerNS.VERSION}`, styles.join(';')], args);
};
Expand Down

0 comments on commit 94ed9d9

Please sign in to comment.