Skip to content

Instantly share code, notes, and snippets.

View arackaf's full-sized avatar
🏠
Working from home

Adam Rackis arackaf

🏠
Working from home
View GitHub Profile
new SWPrecacheWebpackPlugin({
mergeStaticsConfig: true,
filename: "service-worker.js",
importScripts: ["../sw-manual.js"], // <------------------- new
staticFileGlobs: [
"static/bootstrap/css/bootstrap-booklist-build.css",
"static/fontawesome/css/font-awesome-booklist-build.css",
"static/fontawesome/fonts/fontawesome-webfont.woff2",
"static/main-icon2.png",
"util/babelHelpers.min.js",
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Offline Book tracker</title>
<link rel="stylesheet" href="react-redux/static/bootstrap/css/bootstrap-booklist-build.css">
<link rel="stylesheet" href="react-redux/static/fontawesome/css/font-awesome-booklist-build.css">
</head>
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("/service-worker.js");
}
toolbox.router.get(/^https:\/\/images-na.ssl-images-amazon.com/, toolbox.cacheFirst, {
cache: { maxEntries: 500, name: "amazon-images1", maxAgeSeconds: 63072000 },
successResponses: /0|[123].*/
});
// inside your webpack config
const getCache = ({ name, pattern, expires, maxEntries }) => ({
urlPattern: pattern,
handler: "cacheFirst",
options: {
cache: {
maxEntries: maxEntries || 500,
name: name,
maxAgeSeconds: expires || 60 * 60 * 24 * 365 * 2 //2 years
async function a(){
console.log("a");
b();
console.log("b done");
}
async function b(){
console.log("starting b");
await Promise.resolve(res => setTimeout(() => res()), 1000);
console.log("finishing b");
const combineLazyReducers = (reducers, initialState) => {
initialState = initialState || {};
let handler = {
ownKeys(target){
return Array.from(new Set([...Reflect.ownKeys(target), ...Reflect.ownKeys(initialState)]));
},
get(target, key){
return target[key] || (state => state === undefined ? null : state);
},
getOwnPropertyDescriptor(target, key){
const combineLazyReducers = (reducers, initialState) => {
let reducerKeys = new Set(Object.keys(reducers));
Object.keys(initialState)
.filter(k => !reducerKeys.has(k))
.forEach(k => {
reducers[k] = state => state === undefined ? null : state
});
return combineReducers(reducers);
}
const combineLazyReducers = (reducers, initialState) => {
let reducer = combineReducers(reducers);
return (state, action) => ({...initialState, ...reducer(state, action)});
}
const storeInitialState = {
app: { rootA: 10, rootB: 12 },
aModule: { aValue: 'saved A value' },
bModule: { bValue: 'saved B value' },
}
const store = createStore(combineLazyReducers({app: rootReducer}, storeInitialState), storeInitialState);
const asyncReducers = {};
const getNewReducer = newModuleInfo => {