Having js run in the background could open up lots of possibilities for Fuse. I’d suggest having something like Service Workers on the web work in Fuse.
So we would have a FuseJS.BackgroundJS
api, where we would register a “service worker” (idk what it would be called in Fuse):
var BackgroundJS = require('FuseJS/BackgroundJS');
BackgroundJS.register('/backgroundScript.js').then(function(registration) {
// where registration is an object that references the registered script called 'backgroundScript.js' with a whole bunch of useful properties/methods
});
In our backgroundScript.js
it would pretty much be the same as how Service Workers work:
self.addEventListener('install', function() {
// when first installed
});
self.addEventListener('active', function() {
// when first activated
});
self.addEventListener('fetch', function(evt) {
// for every request
// evt.request is a Request object
});
A Cache
api would be exposed as well, etc and whatever is appropriate to run in the background for Fuse
As well the background script wouldn’t be able to export to the UI, it would run on a different thread etc.
And message passing would be implemented
and many more things
Here’s a good diagram of how Service Workers work: https://github.com/delapuente/service-workers-101/
Awesome Google IO presentation on it: https://www.youtube.com/watch?v=cmGr0RszHc8