This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# copied from http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/ | |
git clone <git repository A url> # clone source repository | |
cd <git repository A directory> | |
git remote rm origin # to make sure it doesn't affect the original repository | |
git filter-repo --path <directory 1> # remove all files other than the ones needed | |
mkdir <directory 1> # move them into another directory where they will be stored in the destination repository (if needed) | |
mv * <directory 1> | |
git add . | |
git commit -m "moved to <directory 1>" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
body { | |
display: flex; | |
} | |
.push { | |
width: 2000px; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
body { | |
display: flex; | |
} | |
.push { | |
width: 2000px; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener('error', async err => { | |
// Since we are handling the error here, we must make | |
// sure we log it into the console nonetheless, otherwise | |
// it will be very difficult to understand why your app | |
// is crashing. | |
console.error(err); | |
// If no service worker is available, our work ends here | |
// because we don't need to unregister the service worker | |
// to make sure the user is able to get a newer version of |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
serviceWorker.register({ | |
onUpdate: registration => { | |
setWaitingServiceWorker(registration.waiting); | |
setUpdateAvailable(true); | |
}, | |
onWaiting: waiting => { | |
setWaitingServiceWorker(waiting); | |
setUpdateAvailable(true); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function registerValidSW(swUrl, config) { | |
navigator.serviceWorker | |
.register(swUrl) | |
.then(registration => { | |
// WE ADD THE CODE BELOW | |
if (registration.waiting) { | |
if (config && config.onWaiting) { | |
config.onWaiting(registration.waiting); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function registerValidSW(swUrl, config) { | |
navigator.serviceWorker | |
.register(swUrl) | |
.then(registration => { | |
// WE ADD THE CODE BELOW | |
if (registration.waiting) { | |
if (config && config.onWaiting) { | |
config.onWaiting(registration.waiting); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ServiceWorkerProvider, useServiceWorker } from './useServiceWorker'; | |
const App = () => { | |
const { isUpdateAvailable, updateAssets } = useServiceWorker(); | |
return ( | |
<div> | |
Hello, World! | |
{isUpdateAvailable && ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function registerValidSW(swUrl, config) { | |
navigator.serviceWorker | |
.register(swUrl) | |
.then(registration => { | |
registration.onupdatefound = () => { | |
const installingWorker = registration.installing; | |
if (installingWorker == null) { | |
return; | |
} | |
installingWorker.onstatechange = () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ServiceWorkerContext = React.createContext(); | |
export const ServiceWorkerProvider = ({ children }) => { | |
const [waitingServiceWorker, setWaitingServiceWorker] = useState(null); | |
const [isUpdateAvailable, setUpdateAvailable] = useState(false); | |
React.useEffect(() => { | |
serviceWorker.register({ | |
onUpdate: registration => { | |
setWaitingServiceWorker(registration.waiting); |