mirror of
https://github.com/correl/melpa.git
synced 2024-12-22 19:17:27 +00:00
Memoize package search function
This commit is contained in:
parent
586ef409e3
commit
745f7b6bec
1 changed files with 3 additions and 7 deletions
|
@ -101,13 +101,9 @@
|
||||||
});
|
});
|
||||||
$scope.packageMatcher = function(term) {
|
$scope.packageMatcher = function(term) {
|
||||||
var t = term && term.toLowerCase();
|
var t = term && term.toLowerCase();
|
||||||
var searchTextCache = {};
|
var searchText = _.memoize(function(pkg) {
|
||||||
var searchText = function(pkg) {
|
return _([pkg.name, pkg.description, pkg.source, pkg.version, pkg.sourceURL]).compact().invoke('toLowerCase').valueOf().join(' ');
|
||||||
var v = searchTextCache[pkg.name];
|
}, function(pkg) { return pkg.name; });
|
||||||
if (!v)
|
|
||||||
v = searchTextCache[pkg.name] = _([pkg.name, pkg.description, pkg.source, pkg.version, pkg.sourceURL]).compact().invoke('toLowerCase').valueOf().join(' ');
|
|
||||||
return v;
|
|
||||||
};
|
|
||||||
return function(pkg) {
|
return function(pkg) {
|
||||||
if (!term || !term.match(/\S/)) return true;
|
if (!term || !term.match(/\S/)) return true;
|
||||||
return searchText(pkg).indexOf(t) != -1;
|
return searchText(pkg).indexOf(t) != -1;
|
||||||
|
|
Loading…
Reference in a new issue