Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement #24

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
15 changes: 15 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "react", "prettier"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"prettier"
],
"rules": {
"react/prop-types": "off"
}
}
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/*
node_modules/*
22 changes: 22 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"singleQuote": true,
"trailingComma": "es5",
"tabWidth": 4,
"jsxBracketSameLine": true,
"bracketSpacing": false,
"printWidth": 120,
"overrides": [
{
"files": "*.yml",
"options": {
"tabWidth": 2
}
},
{
"files": "*.json",
"options": {
"tabWidth": 2
}
}
]
}
15 changes: 6 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@

language: node_js
node_js:
- "10"
- "14"
before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.17.3
- export PATH="$HOME/.yarn/bin:$PATH"
before_script:
- cd packages/react-workbox

deploy:
provider: npm
email: "YOUR@EMAIL.ADDRESS"
api_key: $NPM_API_KEY
on:
tags: true
all_branches: true
provider: npm
email: "YOUR@EMAIL.ADDRESS"
api_key: $NPM_API_KEY
on:
tags: true
75 changes: 2 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,6 @@
# react-workbox
Managing status of service worker in the page

## Installation
## API

`Yarn`:
```
yarn add react-workbox
```
`NPM`:
```
npm install react-workbox
```
## Recipes

## Use in create-react-app project
- remove `serviceWorker.unregister()` or `serviceWorker.register()` from `src/index.js`
- delete `src/serverWorker.js`
- Add `WorkBoxProvider` to `render` method in `src/App.js`

```js
import {WorkBoxProvider} from "react-workbox";

render() {
return (
<WorkBoxProvider interval={30 * 1000}>
[...your app content in here]
</WorkBoxProvider>
);
}
```

- Use `UpdateAvailable` or `UpdateActivated` in the app

```js
<UpdateAvailable>
Update Available - Activate the new version first, and refresh the page afterwards
</UpdateAvailable>
<UpdateActivated>
Update Activated - Refresh the page
</UpdateActivated>
```

## Samples

All sample projects are changes to generate new version every minute.

All sample projects check for update in 30 seconds interval.

### Sample 1:
In this sample, only want to notify to the user new version is available, and to activate the new version,
all tabs/pages has to be closed and reopened

This scenario is implemented in https://github.com/NShahri/react-workbox/tree/master/packages/example

### Sample 2:
New service worker will activated asap and will start caching all network requests.
The window will be refreshed on user acceptance.

This scenario is implemented in https://github.com/NShahri/react-workbox/tree/master/packages/example-skip-waiting

### Sample 3:
In this case, a notification will be displayed to user when update is available, and on user confirmation, it will be activated and
the page will be refreshed.
The gap between activating new service worker and refreshing the window is **minimized**.

This scenario is implemented in https://github.com/NShahri/react-workbox/tree/master/packages/example-skip-waiting-with-message

## TODO
- UpdateError
- LastUpdateCheck
- CheckForUpdate
- Tests
- unregister
- logger

## License
MIT
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
roots: ['<rootDir>/src'],
testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
};
58 changes: 53 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,62 @@
{
"name": "react-workbox",
"version": "0.1.0",
"version": "1.0.0-beta-5",
"description": "Manage installation and activation of service worker",
"license": "MIT",
"repository": "https://github.com/NShahri/react-workbox",
"author": "Nima Shahri <https://github.com/NShahri>",
"bugs": {
"url": "https://github.com/NShahri/react-workbox/issues"
},
"private": true,
"workspaces": [
"packages/**"
]
"keywords": [
"workbox",
"service worker",
"service",
"worker",
"react",
"cache",
"PWA",
"progressive",
"progressive web app",
"create react app",
"CRA"
],
"main": "build/cjs/index.js",
"module": "build/es/index.js",
"typings": "build/es/index.d.ts",
"scripts": {
"test": "jest",
"prepublish": "npm run build",
"prebuild": "rimraf build/",
"build": "tsc --project tsconfig.json & tsc --project tsconfig-cjs.json",
"format": "prettier --config ./.prettierrc --write 'src/**/*.{ts,tsx}' && module-grouping 'src/**/*.{ts,tsx}' --write",
"lint": "eslint ./src"
},
"files": [
"build/**/*"
],
"devDependencies": {
"@types/jest": "^27.0.3",
"@types/react": "^17.0.0",
"@types/react-test-renderer": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"eslint": "^8.5.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"jest": "27.4.5",
"module-grouping-cli": "^0.2.9",
"prettier": "^2.2.1",
"react-test-renderer": "^17.0.1",
"rimraf": "3.0.2",
"ts-jest": "^27.1.2",
"typescript": "^4.1.3"
},
"dependencies": {
"react": "^17.0.1",
"tslib": "^2.1.0",
"workbox-window": "^6.0.2"
}
}
21 changes: 0 additions & 21 deletions packages/example-skip-waiting-with-message/LICENSE

This file was deleted.

84 changes: 0 additions & 84 deletions packages/example-skip-waiting-with-message/README.md

This file was deleted.

15 changes: 0 additions & 15 deletions packages/example-skip-waiting-with-message/app.js

This file was deleted.

10 changes: 0 additions & 10 deletions packages/example-skip-waiting-with-message/config-overrides.js

This file was deleted.

32 changes: 0 additions & 32 deletions packages/example-skip-waiting-with-message/package.json

This file was deleted.

Binary file not shown.
Loading