1
Fork 0

Reduce js files size

This commit is contained in:
Guillaume Gomez 2018-05-05 17:06:08 +02:00
parent 72b7c8d291
commit 6a4bdda87b
2 changed files with 31 additions and 26 deletions

View file

@ -413,9 +413,9 @@ impl ToJson for Type {
match self.name {
Some(ref name) => {
let mut data = BTreeMap::new();
data.insert("name".to_owned(), name.to_json());
data.insert("n".to_owned(), name.to_json());
if let Some(ref generics) = self.generics {
data.insert("generics".to_owned(), generics.to_json());
data.insert("g".to_owned(), generics.to_json());
}
Json::Object(data)
},
@ -438,8 +438,12 @@ impl ToJson for IndexItemFunctionType {
Json::Null
} else {
let mut data = BTreeMap::new();
data.insert("inputs".to_owned(), self.inputs.to_json());
data.insert("output".to_owned(), self.output.to_json());
if !self.inputs.is_empty() {
data.insert("i".to_owned(), self.inputs.to_json());
}
if let Some(ref output) = self.output {
data.insert("o".to_owned(), output.to_json());
}
Json::Object(data)
}
}
@ -897,8 +901,8 @@ themePicker.onblur = handleThemeButtonsBlur;
}
fn show_item(item: &IndexItem, krate: &str) -> String {
format!("{{'crate':'{}','ty':{},'name':'{}','desc':'{}','path':'{}'{}}}",
krate, item.ty as usize, item.name, item.desc, item.path,
format!("{{'crate':'{}','ty':{},'name':'{}','desc':'{}','p':'{}'{}}}",
krate, item.ty as usize, item.name, item.desc.replace("'", "\\'"), item.path,
if let Some(p) = item.parent_idx {
format!(",'parent':{}", p)
} else {

View file

@ -462,7 +462,7 @@
if (isType !== true || obj.type) {
var res = buildHrefAndPath(obj);
obj.displayPath = pathSplitter(res[0]);
obj.fullPath = obj.displayPath + obj.name;
obj.fullPath = obj.displayPath + obj.n;
obj.href = res[1];
out.push(obj);
if (out.length >= MAX_RESULTS) {
@ -597,8 +597,8 @@
// match as well.
var lev_distance = MAX_LEV_DISTANCE + 1;
if (val.generics.length > 0) {
if (obj.generics && obj.generics.length >= val.generics.length) {
var elems = obj.generics.slice(0);
if (obj.g && obj.g.length >= val.generics.length) {
var elems = obj.g.slice(0);
var total = 0;
var done = 0;
// We need to find the type that matches the most to remove it in order
@ -630,11 +630,11 @@
// Check for type name and type generics (if any).
function checkType(obj, val, literalSearch) {
var lev_distance = MAX_LEV_DISTANCE + 1;
if (obj.name === val.name) {
if (obj.n === val.name) {
if (literalSearch === true) {
if (val.generics && val.generics.length !== 0) {
if (obj.generics && obj.length >= val.generics.length) {
var elems = obj.generics.slice(0);
if (obj.g && obj.length >= val.generics.length) {
var elems = obj.g.slice(0);
var allFound = true;
var x;
@ -658,7 +658,7 @@
}
// If the type has generics but don't match, then it won't return at this point.
// Otherwise, `checkGenerics` will return 0 and it'll return.
if (obj.generics && obj.generics.length !== 0) {
if (obj.g && obj.g.length !== 0) {
var tmp_lev = checkGenerics(obj, val);
if (tmp_lev <= MAX_LEV_DISTANCE) {
return tmp_lev;
@ -669,22 +669,22 @@
}
// Names didn't match so let's check if one of the generic types could.
if (literalSearch === true) {
if (obj.generics && obj.generics.length > 0) {
for (var x = 0; x < obj.generics.length; ++x) {
if (obj.generics[x] === val.name) {
if (obj.g && obj.g.length > 0) {
for (var x = 0; x < obj.g.length; ++x) {
if (obj.g[x] === val.name) {
return true;
}
}
}
return false;
}
var lev_distance = Math.min(levenshtein(obj.name, val.name), lev_distance);
var lev_distance = Math.min(levenshtein(obj.n, val.name), lev_distance);
if (lev_distance <= MAX_LEV_DISTANCE) {
lev_distance = Math.min(checkGenerics(obj, val), lev_distance);
} else if (obj.generics && obj.generics.length > 0) {
} else if (obj.g && obj.g.length > 0) {
// We can check if the type we're looking for is inside the generics!
for (var x = 0; x < obj.generics.length; ++x) {
lev_distance = Math.min(levenshtein(obj.generics[x], val.name),
for (var x = 0; x < obj.g.length; ++x) {
lev_distance = Math.min(levenshtein(obj.g[x], val.name),
lev_distance);
}
}
@ -696,9 +696,9 @@
function findArg(obj, val, literalSearch) {
var lev_distance = MAX_LEV_DISTANCE + 1;
if (obj && obj.type && obj.type.inputs.length > 0) {
for (var i = 0; i < obj.type.inputs.length; i++) {
var tmp = checkType(obj.type.inputs[i], val, literalSearch);
if (obj && obj.type && obj.type.i && obj.type.i.length > 0) {
for (var i = 0; i < obj.type.i.length; i++) {
var tmp = checkType(obj.type.i[i], val, literalSearch);
if (literalSearch === true && tmp === true) {
return true;
}
@ -714,8 +714,8 @@
function checkReturned(obj, val, literalSearch) {
var lev_distance = MAX_LEV_DISTANCE + 1;
if (obj && obj.type && obj.type.output) {
var tmp = checkType(obj.type.output, val, literalSearch);
if (obj && obj.type && obj.type.o) {
var tmp = checkType(obj.type.o, val, literalSearch);
if (literalSearch === true && tmp === true) {
return true;
}
@ -860,7 +860,7 @@
var fullId = generateId(ty);
// allow searching for void (no output) functions as well
var typeOutput = type.output ? type.output.name : "";
var typeOutput = type.o ? type.o.name : "";
var returned = checkReturned(ty, output, true);
if (output.name === "*" || returned === true) {
var in_args = false;
@ -1029,6 +1029,7 @@
for (var i = 0; i < aliases.length; ++i) {
aliases[i].is_alias = true;
aliases[i].alias = query.raw;
aliases[i].path = aliases[i].p;
var res = buildHrefAndPath(aliases[i]);
aliases[i].displayPath = pathSplitter(res[0]);
aliases[i].fullPath = aliases[i].displayPath + aliases[i].name;