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
| /* | |
| See the readme for detailed guidance, as well as inline comments here. | |
| */ | |
| const Builder = require("systemjs-builder"), | |
| gulp = require("gulp"), | |
| gulpIf = require("gulp-if"), | |
| gulpUglify = require("gulp-uglify"), | |
| gulpRename = require("gulp-rename"), | |
| gulpPlumber = require("gulp-plumber"), |
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
| //entry point | |
| import Class1 from "./junk1"; | |
| import Class2 from "./junk2"; | |
| import Class3 from "./junk3"; | |
| export default function() { | |
| let a = new Class1(); | |
| let b = new Class2(); | |
| let c = new Class3(); |
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
| entry point | |
| import junk1 from "./junk1"; | |
| import junk2 from "./junk2"; | |
| import junk3 from "./junk3"; | |
| export default function() { | |
| return junk1() + junk2() + junk3(); | |
| } | |
| // junk1.js |
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 React, { Component, createElement } from "react"; | |
| import Enzyme, { shallow, render, mount } from "enzyme"; | |
| import Adapter from "enzyme-adapter-react-16"; | |
| import { action, observable, computed } from "mobx"; | |
| import { observer } from "mobx-react"; | |
| Enzyme.configure({ adapter: new Adapter() }); | |
| class Store { | |
| @observable val = 0; | |
| } |
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
| toolbox.router.post(/graphql/, request => { | |
| return fetch(request).then(response => { | |
| let respClone = response.clone(); | |
| setTimeout(() => { | |
| respClone.json().then(resp => { | |
| if (resp && resp.data && resp.data.updateBook && resp.data.updateBook.Book) { | |
| syncBook(resp.data.updateBook.Book); | |
| } | |
| }, 5); | |
| }); |
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
| async function preCacheBookImage(book) { | |
| let smallImage = book.smallImage; | |
| if (!smallImage) return; | |
| let cachedImage = await caches.match(smallImage); | |
| if (cachedImage) return; | |
| if (/https:\/\/s3.amazonaws.com\/my-library-cover-uploads/.test(smallImage)) { | |
| let cache = await caches.open("local-images1"); | |
| let img = await fetch(smallImage, { mode: "no-cors" }); |
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 syncImages(db) { | |
| let tran = db.transaction("books"); | |
| let booksStore = tran.objectStore("books"); | |
| let idx = booksStore.index("imgSync"); | |
| let booksCursor = idx.openCursor(0); | |
| let booksToUpdate = []; | |
| booksCursor.onsuccess = evt => { | |
| let cursor = evt.target.result; | |
| if (!cursor) return runIt(); |
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
| //in web app | |
| if ("serviceWorker" in navigator) { | |
| try { | |
| navigator.serviceWorker.controller.postMessage({ command: "sync-images" }); | |
| } catch (er) {} | |
| } | |
| //in sw-manual.js | |
| self.addEventListener("message", evt => { | |
| if (evt.data && evt.data.command == "sync-images") { |
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 fullSync(page = 1) { | |
| let open = indexedDB.open("books", 1); | |
| // Set up the database schema | |
| open.onsuccess = evt => { | |
| let db = open.result; | |
| fullSyncPage(db, 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
| self.addEventListener("activate", () => { | |
| let open = indexedDB.open("books", 1); | |
| open.onupgradeneeded = evt => { | |
| let db = open.result; | |
| if (!db.objectStoreNames.contains("books") || !db.objectStoreNames.contains("syncInfo")) { | |
| if (!db.objectStoreNames.contains("books")) { | |
| let bookStore = db.createObjectStore("books", { keyPath: "_id" }); | |
| bookStore.createIndex("imgSync", "imgSync", { unique: false }); | |
| } |