This is your captain speaking
please put your phone in airplane mode

Olivier Leplus

 @olivierleplus

Wassim Chegham

@manekinekko

—Pilote

—Copilote

Let's have more fun.

LIVE CODING TIME !

if ('serviceWorker' in navigator) {
  navigator.serviceWorker
    .register('./sw.js')
    .then(registration => { 
        console.log('SW registered');



    });
}
        registration.sync.register('post-action').then(() => {
            console.log('Sync registered');
        });
function postContent () {
    fetch(...)
}

self.addEventListener('sync', function (event) {
  if (event.tag === 'post-action') {
    event.waitUntil(postContent());
  }
});

client.js

sw.js

Internet

This is you

local DB

  • save image to local DB

 

  • register sync
  • trigger sync event

 

  • upload to the internet

IndexedDb

This is a tiny library that mirrors IndexedDB, but replaces the weird IDBRequest objects with promises, plus a couple of other small changes.

 

— Jake Archibald

https://github.com/jakearchibald/idb

Indexed Database API

async/await

 

Promise-based implementation with the advantage of the synchronous-looking generator style.

— Nicolás Bevacqua

https://ponyfoo.com/articles/understanding-javascript-async-await

function getFirstUser() {
    return getUsers().then(function(users) {
        return users[0].name;
    });
}
getFirstUser().then(user => {
    console.log(user);
}
async function getFirstUser() {
    const users = await getUsers();
    return users[0].name;
}

const user = getFirstUser();
const a = await getA();
const b = await getB();
const c = await getC();

 @olivierleplus

@manekinekko

Thanks.

Offline app

By Olivier Leplus

Offline app

  • 1,068