forked from LivelyKernel/lively4-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serviceworker.js
139 lines (109 loc) · 3.3 KB
/
serviceworker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
'use strict';
var l4 = {
importScripts: (function () {
var files = new Set();
return function() {
Array.prototype.forEach.call(arguments, function(fileName) {
if(!files.has(fileName)) {
files.add(fileName);
importScripts(fileName + "?" + Date.now());
}
})
}
})()
};
l4.importScripts('src/sw/core.js');
// --------------------------------------------------------------------
// Loaders
// --------------------------------------------------------------------
l4.importScripts('src/sw/messaging.js');
l4.importScripts('src/sw/logging.js');
l4.importScripts('src/sw/messaging-tasks/github/callback.js'); // #TODO Refactor #JensLincke
console.log('Service Worker: File Start');
self.addEventListener('install', function(event) {
console.log('Service Worker: Install');
});
self.addEventListener('activate', function(event) {
console.log('Service Worker: Activate');
self.clients.claim();
});
l4.importScripts('src/sw/fetch.js');
l4.importScripts('src/sw/fetch-tasks/eval.js');
l4.importScripts('src/sw/fetch-tasks/babel.js');
l4.importScripts('src/sw/fetch-tasks/github.js');
l4.importScripts('src/sw/fetch-tasks/openwindow.js');
/*
TODO: broker/servicelocator for core modules
https://github.com/mochajs/mocha/issues/1457
make them interchangable
var modules;
var broker = function broker(name) {
return (modules && modules[name]) || broker.defaults[name]();
};
broker.defaults = {
runner: function() {
return require('./lib/runner');
},
test: function() {
return require('./lib/test') ;
}
};
broker.init = function init(opts) {
modules = opts;
return broker;
});
module.exports = broker;
then calling:
require('broker').init(modules);
require('broker')('runner');
*/
/*
TODO: plugin architecture
chai.use(require('some-chai-plugin'));
mocha.use(require('plugin-module')(opts));
thenable plugins
l4.use().then();
*/
/*
TODO: configuration via code, not json as code is more powerful, e.g.
// karma.conf.js
module.exports = function(karma) {
karma.set({
browsers: [process.env.TRAVIS ? 'Firefox' : 'Chrome']
});
}
// angular
'use strict';
var angularFiles = require('./angularFiles');
var sharedConfig = require('./karma-shared.conf');
module.exports = function(config) {
sharedConfig(config, {testName: 'AngularJS: jqLite', logFile: 'karma-jqlite.log'});
config.set({
files: angularFiles.mergeFilesFor('karma'),
exclude: angularFiles.mergeFilesFor('karmaExclude'),
junitReporter: {
outputFile: 'test_out/jqlite.xml',
suite: 'jqLite'
}
});
};
*/
console.log('Service Worker: File End');
// --------------------------------------------------------------------
// Usage
// --------------------------------------------------------------------
(function() {
var headers = new Headers();
//headers.append();
var request = new Request('https://code.jquery.com/jquery-2.1.4.js', {
method: 'GET',
headers: headers
});
fetch(request).then(function(response) {
console.log('#############################################################');
console.log(response);
}).catch(function(error) {
console.log('#############################################################');
console.log(error);
});
})();