Commit 24cbe02c authored by 神楽坂玲奈's avatar 神楽坂玲奈

fix sw

parent 0fb3e190
{ {
"name": "mycard-mobile", "name": "mycard-mobile",
"version": "1.0.24", "version": "1.0.25",
"license": "UNLISENCED", "license": "UNLISENCED",
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"start": "ng serve --aot", "start": "ng serve --aot",
"build": "ng build --i18n-locale zh-CN --base-href /mobile/ --prod", "build": "ng build --i18n-locale zh-CN --base-href /mobile/ --prod && npm run fuck",
"build:dev": "ng build --i18n-locale zh-CN --base-href /mobile2/ --prod", "build:dev": "ng build --i18n-locale zh-CN --base-href /mobile2/ --prod && npm run fuck",
"fuck": "patch -i service-worker.patch dist/ngsw-worker.js",
"postinstall": "patch -i webpack.patch -p0 -t", "postinstall": "patch -i webpack.patch -p0 -t",
"lint": "ng lint" "lint": "ng lint"
}, },
......
4c4,39
<
---
> const waitUntil = ExtendableEvent.prototype.waitUntil;
> const respondWith = FetchEvent.prototype.respondWith;
> const promisesMap = new WeakMap();
>
> ExtendableEvent.prototype.waitUntil = function(promise) {
> const extendableEvent = this;
> let promises = promisesMap.get(extendableEvent);
>
> if (promises) {
> promises.push(Promise.resolve(promise));
> return;
> }
>
> promises = [Promise.resolve(promise)];
> promisesMap.set(extendableEvent, promises);
>
> // call original method
> return waitUntil.call(extendableEvent, Promise.resolve().then(function processPromises() {
> const len = promises.length;
>
> // wait for all to settle
> return Promise.all(promises.map(p => p.catch(()=>{}))).then(() => {
> // have new items been added? If so, wait again
> if (promises.length != len) return processPromises();
> // we're done!
> promisesMap.delete(extendableEvent);
> // reject if one of the promises rejected
> return Promise.all(promises);
> });
> }));
> };
>
> FetchEvent.prototype.respondWith = function(promise) {
> this.waitUntil(promise);
> return respondWith.call(this, promise);
> };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment