bugfix
This commit is contained in:
parent
c292767a0d
commit
9e687ee3c1
@ -50,6 +50,51 @@ dispatch_event:
|
||||
params:
|
||||
*/
|
||||
|
||||
bricks.str2data = function(s, d){
|
||||
/* fmt like
|
||||
'my name is ${name}, ${age:type}'
|
||||
type can be:
|
||||
int, str, json
|
||||
*/
|
||||
funcs = {
|
||||
'json':JSON.stringify
|
||||
}
|
||||
var regex = /\${(\w+)(?::(int|str|json))?}/;
|
||||
var match = s.match(regex)
|
||||
if (match){
|
||||
var key = match[1];
|
||||
var typ = match[2];
|
||||
var ss = '${' + key;
|
||||
if (typ != ''){
|
||||
ss += ':' + typ;
|
||||
}
|
||||
ss += '}';
|
||||
if (s == ss){
|
||||
if (!d.hasOwnProperty(key)){
|
||||
return null;
|
||||
}
|
||||
if (typ == ''){
|
||||
return d[key];
|
||||
}
|
||||
var f = funcs[typ];
|
||||
if (f){
|
||||
return f(d[key]);
|
||||
}
|
||||
return d[key];
|
||||
}
|
||||
return s.replace(regex, (k, key, typ) => {
|
||||
if (d.hasOwnProperty(key){
|
||||
var f = funcs[typ];
|
||||
if (f){
|
||||
return f(d[key]);
|
||||
}
|
||||
return d[key];
|
||||
}
|
||||
return '';
|
||||
});
|
||||
}
|
||||
return s;
|
||||
}
|
||||
bricks.apply_data = function(desc, data){
|
||||
var tmpl = JSON.stringify(desc);
|
||||
var s = bricks.obj_fmtstr(data, tmpl);
|
||||
|
@ -2,6 +2,20 @@ var bricks = window.bricks || {};
|
||||
function url_params(data) {
|
||||
return Object.keys(data).map(key => `${key}=${encodeURIComponent(data[key])}`).join('&');
|
||||
}
|
||||
/*
|
||||
async function doit() {
|
||||
const response = await fetch("http://localhost:3000")
|
||||
const reader = response.body.getReader()
|
||||
const decoder = new TextDecoder()
|
||||
let result = await reader.read()
|
||||
while (!result.done) {
|
||||
const text = decoder.decode(result.value)
|
||||
console.log("chunk is", text)
|
||||
result = await reader.read()
|
||||
}
|
||||
}
|
||||
// chunked response handle
|
||||
*/
|
||||
bricks.HttpText = class {
|
||||
constructor(headers){
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user