don't use the store until it's ready to be used
parent
fffa9acf15
commit
600f3151e9
|
@ -112,22 +112,26 @@ define([
|
|||
});
|
||||
};
|
||||
|
||||
Cryptpad.getRecentPads(function (err, recentPads) {
|
||||
if (err) {
|
||||
console.log("unable to get recent pads");
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
Cryptpad.ready(function () {
|
||||
console.log("ready");
|
||||
Cryptpad.getRecentPads(function (err, recentPads) {
|
||||
console.log(recentPads);
|
||||
if (err) {
|
||||
console.log("unable to get recent pads");
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (recentPads.length) {
|
||||
recentPads.sort(Cryptpad.mostRecent);
|
||||
makeRecentPadsTable(recentPads);
|
||||
}
|
||||
if (recentPads.length) {
|
||||
recentPads.sort(Cryptpad.mostRecent);
|
||||
makeRecentPadsTable(recentPads);
|
||||
}
|
||||
|
||||
if (hasRecent) {
|
||||
$('table').attr('style', '');
|
||||
$tryit.text(Messages.recentPads);
|
||||
}
|
||||
if (hasRecent) {
|
||||
$('table').attr('style', '');
|
||||
$tryit.text(Messages.recentPads);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -65,5 +65,11 @@ define(function () {
|
|||
cb(void 0, Object.keys(localStorage));
|
||||
};
|
||||
|
||||
Store.ready = function (f) {
|
||||
if (typeof(f) === 'function') {
|
||||
f(void 0, Store);
|
||||
}
|
||||
};
|
||||
|
||||
return Store;
|
||||
});
|
||||
|
|
|
@ -610,10 +610,18 @@ define([
|
|||
|
||||
var interval = 100;
|
||||
|
||||
var second = function (CM) {
|
||||
Cryptpad.ready(function (err, env) {
|
||||
// TODO handle error
|
||||
andThen(CM);
|
||||
});
|
||||
};
|
||||
|
||||
var first = function () {
|
||||
if (ifrw.CodeMirror) {
|
||||
// it exists, call your continuation
|
||||
andThen(ifrw.CodeMirror);
|
||||
//andThen(ifrw.CodeMirror);
|
||||
second(ifrw.CodeMirror);
|
||||
} else {
|
||||
console.log("CodeMirror was not defined. Trying again in %sms", interval);
|
||||
// try again in 'interval' ms
|
||||
|
|
|
@ -13,6 +13,23 @@ define([
|
|||
*/
|
||||
var $ = window.jQuery;
|
||||
|
||||
var store;
|
||||
|
||||
var getStore = function () {
|
||||
if (!store) {
|
||||
throw new Error("Store is not ready!");
|
||||
}
|
||||
return store;
|
||||
};
|
||||
|
||||
Store.ready(function (err, Store) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
store = Store;
|
||||
});
|
||||
|
||||
var common = {};
|
||||
|
||||
var isArray = function (o) { return Object.prototype.toString.call(o) === '[object Array]'; };
|
||||
|
@ -76,20 +93,20 @@ define([
|
|||
};
|
||||
|
||||
var setPadAttribute = common.setPadAttribute = function (attr, value, cb) {
|
||||
Store.set([getHash(), attr].join('.'), value, function (err, data) {
|
||||
getStore().set([getHash(), attr].join('.'), value, function (err, data) {
|
||||
cb(err, data);
|
||||
});
|
||||
};
|
||||
|
||||
var getPadAttribute = common.getPadAttribute = function (attr, cb) {
|
||||
Store.get([getHash(), attr].join('.'), function (err, data) {
|
||||
getStore().get([getHash(), attr].join('.'), function (err, data) {
|
||||
cb(err, data);
|
||||
});
|
||||
};
|
||||
|
||||
/* fetch and migrate your pad history from localStorage */
|
||||
var getRecentPads = common.getRecentPads = function (cb) {
|
||||
Store.get(storageKey, function (err, recentPads) {
|
||||
getStore().get(storageKey, function (err, recentPads) {
|
||||
if (isArray(recentPads)) {
|
||||
cb(void 0, migrateRecentPads(recentPads));
|
||||
return;
|
||||
|
@ -100,7 +117,7 @@ define([
|
|||
|
||||
/* commit a list of pads to localStorage */
|
||||
var setRecentPads = common.setRecentPads = function (pads, cb) {
|
||||
Store.set(storageKey, pads, function (err, data) {
|
||||
getStore().set(storageKey, pads, function (err, data) {
|
||||
cb(err, data);
|
||||
});
|
||||
};
|
||||
|
@ -129,7 +146,7 @@ define([
|
|||
return;
|
||||
}
|
||||
|
||||
Store.keys(function (err, keys) {
|
||||
getStore().keys(function (err, keys) {
|
||||
if (err) {
|
||||
cb(err);
|
||||
return;
|
||||
|
@ -264,6 +281,25 @@ define([
|
|||
});
|
||||
};
|
||||
|
||||
// local name?
|
||||
common.ready = function (f) {
|
||||
var state = 0;
|
||||
|
||||
var env = {};
|
||||
|
||||
var cb = function () {
|
||||
state--;
|
||||
if (!state) {
|
||||
f(void 0, env);
|
||||
}
|
||||
};
|
||||
|
||||
state++;
|
||||
Store.ready(function (err, store) {
|
||||
env.store = store;
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
var fixFileName = common.fixFileName = function (filename) {
|
||||
return filename.replace(/ /g, '-').replace(/\//g, '_');
|
||||
|
|
|
@ -623,11 +623,19 @@ define([
|
|||
};
|
||||
|
||||
var interval = 100;
|
||||
var second = function (Ckeditor) {
|
||||
Cryptpad.ready(function (err, env) {
|
||||
// TODO handle error
|
||||
andThen(Ckeditor);
|
||||
});
|
||||
};
|
||||
|
||||
var first = function () {
|
||||
Ckeditor = ifrw.CKEDITOR;
|
||||
|
||||
if (Ckeditor) {
|
||||
andThen(Ckeditor);
|
||||
//andThen(Ckeditor);
|
||||
second(Ckeditor);
|
||||
} else {
|
||||
console.log("Ckeditor was not defined. Trying again in %sms",interval);
|
||||
setTimeout(first, interval);
|
||||
|
|
|
@ -602,17 +602,22 @@ define([
|
|||
crypto: Crypto.createEncryptor(secret.key),
|
||||
};
|
||||
|
||||
var rt = module.rt = Listmap.create(config);
|
||||
rt.proxy.on('create', function (info) {
|
||||
var realtime = module.realtime = info.realtime;
|
||||
window.location.hash = info.channel + secret.key;
|
||||
module.patchText = TextPatcher.create({
|
||||
realtime: realtime,
|
||||
logging: true,
|
||||
// don't initialize until the store is ready.
|
||||
Cryptpad.ready(function () {
|
||||
|
||||
var rt = module.rt = Listmap.create(config);
|
||||
rt.proxy.on('create', function (info) {
|
||||
var realtime = module.realtime = info.realtime;
|
||||
window.location.hash = info.channel + secret.key;
|
||||
module.patchText = TextPatcher.create({
|
||||
realtime: realtime,
|
||||
logging: true,
|
||||
});
|
||||
}).on('ready', ready)
|
||||
.on('disconnect', function () {
|
||||
setEditable(false);
|
||||
Cryptpad.alert("Network connection lost!");
|
||||
});
|
||||
}).on('ready', ready)
|
||||
.on('disconnect', function () {
|
||||
setEditable(false);
|
||||
Cryptpad.alert("Network connection lost!");
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue