Skip to content

Commit

Permalink
添加一个统一的去掉内部方法 uniqSet
Browse files Browse the repository at this point in the history
  • Loading branch information
RubyLouvre committed Aug 22, 2014
1 parent 7bc046b commit d72e258
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 172 deletions.
32 changes: 13 additions & 19 deletions avalon.js
Expand Up @@ -2175,15 +2175,7 @@
.replace(rnumber, "")
.replace(rcomma, "")
.split(/^$|,+/)
var vars = [],
unique = {}
for (var i = 0; i < match.length; ++i) {
var variable = match[i]
if (!unique[variable]) {
unique[variable] = vars.push(variable)
}
}
return cacheVars(key, vars)
return cacheVars(key, uniqSet(match))
}

//添加赋值语句
Expand All @@ -2202,21 +2194,22 @@
}
return ret
}

function uniqVmodels(arr) {
var uniq = {}
return arr.filter(function(el) {
if (!uniq[el.$id]) {
uniq[el.$id] = 1
return true

function uniqSet(array) {
var ret = [], unique = {}
for (var i = 0; i < array.length; i++) {
var el = array[i]
var id = el && typeof el.$id === "string" ? el.$id : el
if (!unique[id]) {
unique[id] = ret.push(el)
}
})
}
return ret
}
//缓存求值函数,以便多次利用

function createCache(maxLength) {
var keys = []

function cache(key, value) {
if (keys.push(key) > maxLength) {
delete cache[keys.shift()]
Expand All @@ -2225,6 +2218,7 @@
}
return cache;
}

var cacheExprs = createCache(256)
//取得求值函数及其传参
var rduplex = /\w\[.*\]|\w\.\w/
Expand All @@ -2242,7 +2236,7 @@
args = [],
prefix = ""
//args 是一个对象数组, names 是将要生成的求值函数的参数
scopes = uniqVmodels(scopes)
scopes = uniqSet(scopes)
for (var i = 0, sn = scopes.length; i < sn; i++) {
if (vars.length) {
var name = "vm" + expose + "_" + i
Expand Down

0 comments on commit d72e258

Please sign in to comment.