toString must be stringy!

This commit is contained in:
Mark Nadal 2022-11-30 23:27:51 -08:00
parent 2d3993125d
commit 73d54b6271
2 changed files with 36 additions and 4 deletions

View File

@ -22,11 +22,11 @@ var sT = setTimeout, B = sT.Book || (sT.Book = function(text){
b.get = get;
b.all = {};
return b;
}), PAGE = 2**16;//2**12;
}), PAGE = 2**12;
function page(word){
var b = this, l = b.list, i = spot(B.encode(word), l), p = l[i];
if('string' == typeof p){ l[i] = p = {size: -1, first: p, substring: sub, toString: to, book: b} }
if('string' == typeof p){ l[i] = p = {size: -1, first: p, substring: sub, toString: to, book: b} } // TODO: test, how do we arrive at this condition again?
return p;
// TODO: BUG! What if we get the page, it turns out to be too big & split, we must then RE get the page!
}
@ -118,7 +118,7 @@ function sub(i,j){ return (this.first||this.word||(from(this)||'')[0]||'').subst
function to(){ return this.text = this.text || text(this) }
function join(){ return this.join('|') }
function text(p){
if(!p.list){ return p.from || '' }
if(!p.list){ return (p.from||'')+'' }
if(!p.from){ return '|'+((p.list && (p.list = p.list.sort()).join('|'))||'')+'|' }
return '|'+from(p).concat(p.list).sort().join('|')+'|';
}

View File

@ -164,3 +164,35 @@
});
}
}());
;(function () { // temporary fs storage plugin, needs to be refactored to use the actual RAD plugin interface.
var lS;
try { lS = localStorage } catch (e) { };
if (!lS) { return }
var sT = setTimeout, RAD = sT.RAD;
RAD.put = function (file, data, cb) {
lS[file] = data;
cb(null, 1);
}
RAD.get = function (file, cb) {
cb(null, lS[file]);
}
}());
;(function(){
return;
var get;
try { get = fetch } catch (e) { };
if (!get) { return }
var sT = setTimeout, RAD = sT.RAD;
RAD.put = function(file, data, cb){ cb(401) }
RAD.get = async function(file, cb){
var t = (await (await fetch('http://localhost:8765/gun/'+file)).text());
console.log("???file?", file, t);
if('404' == t){ cb(); return }
cb(null, t);
}
}());