Front end of the Slack clone application.

serviceworker-client.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*globals importScripts:true, self:true */
  2. importScripts("/dist/localforage.js");
  3. self.onmessage = function(messageEvent) {
  4. return localforage
  5. .setDriver(messageEvent.data.driver)
  6. .then(function() {
  7. return localforage.setItem('service worker', messageEvent.data.value);
  8. })
  9. .then(function() {
  10. return localforage.getItem('service worker');
  11. })
  12. .then(function(value) {
  13. messageEvent
  14. .ports[0]
  15. .postMessage({
  16. body: value + ' using ' + localforage.driver()
  17. });
  18. })
  19. .catch(function(error) {
  20. messageEvent
  21. .ports[0]
  22. .postMessage({
  23. error: JSON.stringify(error),
  24. body: error,
  25. fail: true
  26. });
  27. });
  28. };
  29. self.oninstall = function(event) {
  30. event.waitUntil(
  31. localforage
  32. .setItem('service worker registration', 'serviceworker present')
  33. .then(function(value) {
  34. console.log(value);
  35. })
  36. );
  37. };