@qbix/q.js 1.0.8 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Metrics.js +28 -4
- package/dist/Metrics.min.js +18 -8
- package/dist/Q.js +3798 -502
- package/dist/Q.min.js +460 -373
- package/dist/Q.minimal.js +89 -0
- package/dist/Q.minimal.min.js +125 -123
- package/package.json +1 -1
package/dist/Q.minimal.js
CHANGED
|
@@ -5950,6 +5950,95 @@ Q.page = function _Q_page(page, handler, key) {
|
|
|
5950
5950
|
* @param {boolean} [options.isCordova]
|
|
5951
5951
|
* @return {boolean}
|
|
5952
5952
|
*/
|
|
5953
|
+
/**
|
|
5954
|
+
* Service worker support for the minimal build.
|
|
5955
|
+
*
|
|
5956
|
+
* The minimal build calls _startCachingWithServiceWorker() and reads
|
|
5957
|
+
* Q.ServiceWorker.started and .onActive from Q.init, but neither the function
|
|
5958
|
+
* nor the object was carried over from the full Q.js -- so Q.init() threw
|
|
5959
|
+
* before it finished, and nothing after it ran.
|
|
5960
|
+
*
|
|
5961
|
+
* This is the smallest thing that makes those three call sites correct. It
|
|
5962
|
+
* registers a worker when Q.info.serviceWorkerUrl is set and does nothing
|
|
5963
|
+
* when it is not, which is the normal case for an embedded widget or a
|
|
5964
|
+
* standalone page. Deliberately no cache priming: that is what the full
|
|
5965
|
+
* build's _startCachingWithServiceWorker does, and a minimal build has no
|
|
5966
|
+
* business shipping it.
|
|
5967
|
+
*/
|
|
5968
|
+
Q.ServiceWorker = {
|
|
5969
|
+
|
|
5970
|
+
/**
|
|
5971
|
+
* Whether registration was attempted. Q.init pushes a "serviceWorker"
|
|
5972
|
+
* readiness check when this is true, so it must stay false unless a
|
|
5973
|
+
* worker is really being registered -- otherwise Q.init waits forever
|
|
5974
|
+
* for an onActive that will never fire.
|
|
5975
|
+
*/
|
|
5976
|
+
started: false,
|
|
5977
|
+
|
|
5978
|
+
/**
|
|
5979
|
+
* @event onActive
|
|
5980
|
+
*/
|
|
5981
|
+
onActive: new Q.Event(),
|
|
5982
|
+
|
|
5983
|
+
/**
|
|
5984
|
+
* Register the service worker at Q.info.serviceWorkerUrl, if there is one.
|
|
5985
|
+
* @method start
|
|
5986
|
+
* @param {Function} [callback] receives (worker, registration), or
|
|
5987
|
+
* (false) when there is no worker -- both the unsupported and the
|
|
5988
|
+
* unconfigured case, which the full build signalled inconsistently
|
|
5989
|
+
* @param {Object} [options]
|
|
5990
|
+
*/
|
|
5991
|
+
start: function (callback, options) {
|
|
5992
|
+
options = options || {};
|
|
5993
|
+
if (!('serviceWorker' in navigator)) {
|
|
5994
|
+
Q.handle(callback, null, [false]);
|
|
5995
|
+
Q.ServiceWorker.onActive.handle(false);
|
|
5996
|
+
return;
|
|
5997
|
+
}
|
|
5998
|
+
var src = Q.info && Q.info.serviceWorkerUrl;
|
|
5999
|
+
if (!src) {
|
|
6000
|
+
// No worker configured. Signal exactly as the unsupported branch
|
|
6001
|
+
// does. The full build returned true here, and its caller took
|
|
6002
|
+
// that first argument as the worker and called
|
|
6003
|
+
// true.postMessage() -- "worker.postMessage is not a function".
|
|
6004
|
+
Q.handle(callback, null, [false]);
|
|
6005
|
+
Q.ServiceWorker.onActive.handle(false);
|
|
6006
|
+
return;
|
|
6007
|
+
}
|
|
6008
|
+
Q.ServiceWorker.started = true;
|
|
6009
|
+
navigator.serviceWorker.register(src)
|
|
6010
|
+
.then(function (registration) {
|
|
6011
|
+
if (options.update && registration.update) {
|
|
6012
|
+
registration.update();
|
|
6013
|
+
}
|
|
6014
|
+
var worker = registration.active
|
|
6015
|
+
|| registration.waiting
|
|
6016
|
+
|| registration.installing;
|
|
6017
|
+
Q.handle(callback, Q.ServiceWorker, [worker, registration]);
|
|
6018
|
+
Q.ServiceWorker.onActive.handle(worker, registration);
|
|
6019
|
+
})
|
|
6020
|
+
.catch(function (err) {
|
|
6021
|
+
// Registration can fail for reasons the page cannot control --
|
|
6022
|
+
// no HTTPS, a 404 on the script, a scope mismatch. None of them
|
|
6023
|
+
// should stop the rest of Q from initialising, and started must
|
|
6024
|
+
// go back to false or Q.init keeps waiting on a check that will
|
|
6025
|
+
// never be filled.
|
|
6026
|
+
Q.ServiceWorker.started = false;
|
|
6027
|
+
console.warn('Q.ServiceWorker.start:', err && err.message || err);
|
|
6028
|
+
Q.handle(callback, null, [false]);
|
|
6029
|
+
Q.ServiceWorker.onActive.handle(false);
|
|
6030
|
+
});
|
|
6031
|
+
}
|
|
6032
|
+
|
|
6033
|
+
};
|
|
6034
|
+
|
|
6035
|
+
function _startCachingWithServiceWorker() {
|
|
6036
|
+
// The full build primes the worker's cache with inlined styles and
|
|
6037
|
+
// scripts here. The minimal build has nothing to prime, so this only
|
|
6038
|
+
// registers -- and registers nothing when no URL is configured.
|
|
6039
|
+
Q.ServiceWorker.start(null, { update: true });
|
|
6040
|
+
}
|
|
6041
|
+
|
|
5953
6042
|
Q.init = function _Q_init(options) {
|
|
5954
6043
|
if (Q.init.called) {
|
|
5955
6044
|
return false;
|