Add support for async store when WebWorker is not available
This commit is contained in:
@@ -7,13 +7,12 @@ define([
|
|||||||
'/common/common-constants.js',
|
'/common/common-constants.js',
|
||||||
'/common/common-feedback.js',
|
'/common/common-feedback.js',
|
||||||
'/common/outer/local-store.js',
|
'/common/outer/local-store.js',
|
||||||
//'/common/outer/store-rpc.js',
|
|
||||||
'/common/outer/worker-channel.js',
|
'/common/outer/worker-channel.js',
|
||||||
|
|
||||||
'/customize/application_config.js',
|
'/customize/application_config.js',
|
||||||
'/bower_components/nthen/index.js',
|
'/bower_components/nthen/index.js',
|
||||||
], function (Config, Messages, Util, Hash,
|
], function (Config, Messages, Util, Hash,
|
||||||
Messaging, Constants, Feedback, LocalStore, /*AStore, */Channel,
|
Messaging, Constants, Feedback, LocalStore, Channel,
|
||||||
AppConfig, Nthen) {
|
AppConfig, Nthen) {
|
||||||
|
|
||||||
/* This file exposes functionality which is specific to Cryptpad, but not to
|
/* This file exposes functionality which is specific to Cryptpad, but not to
|
||||||
@@ -867,8 +866,13 @@ define([
|
|||||||
worker.postMessage(data);
|
worker.postMessage(data);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// TODO fallback no webworker?
|
require(['/common/outer/noworker.js'], waitFor2(function (NoWorker) {
|
||||||
console.error('NO SW OR WW');
|
NoWorker.onMessage(function (data) {
|
||||||
|
msgEv.fire({data: data});
|
||||||
|
});
|
||||||
|
postMsg = function (d) { setTimeout(function () { NoWorker.query(d); }); };
|
||||||
|
NoWorker.create();
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}).nThen(function () {
|
}).nThen(function () {
|
||||||
Channel.create(msgEv, postMsg, function (chan) {
|
Channel.create(msgEv, postMsg, function (chan) {
|
||||||
|
|||||||
@@ -9,7 +9,17 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var create = function (onMsg, postMsg, cb, isWorker) {
|
var create = function (onMsg, postMsg, cb, isWorker) {
|
||||||
|
if (!isWorker) {
|
||||||
|
var chanLoaded = false;
|
||||||
|
var waitingData = [];
|
||||||
|
onMsg.reg(function (data) {
|
||||||
|
if (chanLoaded) { return; }
|
||||||
|
waitingData.push(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var evReady = Util.mkEvent(true);
|
var evReady = Util.mkEvent(true);
|
||||||
|
|
||||||
var handlers = {};
|
var handlers = {};
|
||||||
var queries = {};
|
var queries = {};
|
||||||
|
|
||||||
@@ -123,6 +133,12 @@ define([
|
|||||||
});
|
});
|
||||||
if (isWorker) {
|
if (isWorker) {
|
||||||
evReady.fire();
|
evReady.fire();
|
||||||
|
} else {
|
||||||
|
chanLoaded = true;
|
||||||
|
waitingData.forEach(function (d) {
|
||||||
|
onMsg.fire(d);
|
||||||
|
});
|
||||||
|
waitingData = [];
|
||||||
}
|
}
|
||||||
cb(chan);
|
cb(chan);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user