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

Cached if there are no cached results #545

Open
wants to merge 2 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
12 changes: 6 additions & 6 deletions client/absolute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/

import CacheManager from './cache/cache_manager';
import PushManager from './push/push_manager';
import Notification from './notification/notification_manager';
import IndexedDB from './indexeddb/indexeddb';
import Notification from './notification/notification_manager';
import PushManager from './push/push_manager';

export default class absolute {
static cache: CacheManager = new CacheManager();
static push: PushManager = new PushManager();
static notification: Notification = new Notification();
static indexeddb: IndexedDB = new IndexedDB();
public static cache: CacheManager = new CacheManager();
public static push: PushManager = new PushManager();
public static notification: Notification = new Notification();
public static indexeddb: IndexedDB = new IndexedDB();
}
2 changes: 1 addition & 1 deletion client/cache/cache_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class CacheManager {
this.register('cache_service_worker.js');
}

async register(worker: string): Promise<void> {
public async register(worker: string): Promise<void> {
if (navigator.serviceWorker) {
navigator.serviceWorker.register(worker).then((registration: ServiceWorkerRegistration) => {
// registration worked
Expand Down
12 changes: 11 additions & 1 deletion client/cache/cache_service_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ self_.addEventListener('install', (event) => {
self_.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
return response || fetch(event.request).then(function (response) {
const responseClone = response.clone();

caches.open('absolute-cache-v1').then(function (cache) {
cache.put(event.request, responseClone);
});
return response;
}).catch(function () {
//TODO(sapzape): Add code to return in a fallback response.
return;
});
})
);
});
2 changes: 1 addition & 1 deletion client/indexeddb/indexeddb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ test('absolute.indexeddb.get()', async () => {

test('absolute.indexeddb.remove()', async () => {
expect(await absolute.indexeddb.remove('test_key')).toBe(null);
});
});
8 changes: 4 additions & 4 deletions client/indexeddb/indexeddb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
* limitations under the License.
*/

export default class IndexedDB{
export default class IndexedDB {

constructor() {}

async set(key: string, value: object): Promise<boolean> {
public async set(key: string, value: object): Promise<boolean> {
// Not implemented yet
return false;
}

async get(key: string): Promise<object> {
public async get(key: string): Promise<object> {
// Not implemented yet
return null;
}

async remove(key: string): Promise<object> {
public async remove(key: string): Promise<object> {
// Not implemented yet
return null;
}
Expand Down
8 changes: 4 additions & 4 deletions client/notification/notification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import { } from 'jest';
import absolute from '../absolute';

test('absolute.notification.create()', async () => {
let NotificationEvent = new Event("click");
const NotificationEvent = new Event('click');
expect(await absolute.notification.create(NotificationEvent)).toBe(false);
});
test('absolute.notification.close()', async () => {
let NotificationEvent = new Event("click");
const NotificationEvent = new Event('click');
expect(await absolute.notification.close(NotificationEvent)).toBe(false);
});
test('absolute.notification.processClickEvent()', async () => {
let NotificationEvent = new Event("click");
const NotificationEvent = new Event('click');
expect(await absolute.notification.processClickEvent(NotificationEvent)).toBe(false);
});
});
8 changes: 4 additions & 4 deletions client/notification/notification_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ export default class Notification {
constructor() {
}

async create(NotificationEvent: Event): Promise<boolean> {
public async create(NotificationEvent: Event): Promise<boolean> {
// Not implemented yet
return false;
}
async close(NotificationEvent: Event): Promise<boolean> {
public async close(NotificationEvent: Event): Promise<boolean> {
// Not implemented yet
return false;
}
async processClickEvent(NotificationEvent: Event): Promise<boolean> {
public async processClickEvent(NotificationEvent: Event): Promise<boolean> {
// Not implemented yet
return false;
}
}
}
2 changes: 1 addition & 1 deletion client/push/push_manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test('absolute.push.isRegistered()', async() => {
});

test('absolute.push.register()', async() => {
const registered: Promise<any> = await absolute.push.register('test_key')
const registered: Promise<{}> = await absolute.push.register('test_key');
expect(registered).rejects.toBe(null);
});

Expand Down
22 changes: 11 additions & 11 deletions client/push/push_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class PushManager {

constructor() {}

async isRegistered(): Promise<boolean> {
public async isRegistered(): Promise<boolean> {
if (!navigator.serviceWorker) {
return false;
}
Expand All @@ -32,21 +32,21 @@ export default class PushManager {
if (subscription) {
return true;
}

return false;
})
.catch((error: Error) => {
// Not implemented yet
})
});
})
.catch((error: Error) => {
// Not implemented yet
})
});

return false;
}

async register(key: string): Promise<string> {
public async register(key: string): Promise<string> {
if (navigator.serviceWorker) {
navigator.serviceWorker.register('/push_service_worker.js')
.then((registration: ServiceWorkerRegistration) => {
Expand All @@ -72,8 +72,8 @@ export default class PushManager {
})
.catch((error: Error) => {
// Not implemented yet
})
})
});
});

})
.catch((error: Error) => {
Expand All @@ -84,7 +84,7 @@ export default class PushManager {
return null;
}

async unregister(): Promise<boolean> {
public async unregister(): Promise<boolean> {
if (!navigator.serviceWorker) {
return false;
}
Expand All @@ -96,16 +96,16 @@ export default class PushManager {
if (subscription) {
subscription.unsubscribe();
return true;
}
}
return false;
})
.catch((error: Error) => {
// Not implemented yet
})
});
})
.catch((error: Error) => {
// Not implemented yet
})
});

return false;
}
Expand Down