Skip to content

Commit

Permalink
fix 短路与 短路或引发依赖收集失败的BUG RubyLouvre#583
Browse files Browse the repository at this point in the history
  • Loading branch information
RubyLouvre committed Nov 19, 2014
1 parent e5ccdac commit bfa45a2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
26 changes: 22 additions & 4 deletions avalon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2404,14 +2404,14 @@
for (var i = vars.length, prop; prop = vars[--i]; ) {
if (scope.hasOwnProperty(prop)) {
ret.push(prop + prefix + prop)
data.vars.push(prop)
if (data.type === "duplex") {
vars.get = name + "." + prop
}
vars.splice(i, 1)
}
}
return ret

}

function uniqSet(array) {
Expand Down Expand Up @@ -2449,7 +2449,7 @@
var dataType = data.type
var filters = data.filters ? data.filters.join("") : ""
var exprId = scopes.map(function(el) {
return el.$id.replace(rproxy, "$1")
return String(el.$id).replace(rproxy, "$1")
}) + code + dataType + filters
var vars = getVariables(code).concat(),
assigns = [],
Expand All @@ -2458,6 +2458,7 @@
prefix = ""
//args 是一个对象数组, names 是将要生成的求值函数的参数
scopes = uniqSet(scopes)
data.vars = []
for (var i = 0, sn = scopes.length; i < sn; i++) {
if (vars.length) {
var name = "vm" + expose + "_" + i
Expand All @@ -2469,6 +2470,20 @@
if (!assigns.length && dataType === "duplex") {
return
}
//https://github.com/RubyLouvre/avalon/issues/583
data.vars.forEach(function(v) {
var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig")
code = code.replace(reg, function(_) {
var c = _.charAt(v.length)
if (c === "." || c === "[") {
var name = "var" + String(Math.random()).replace(/^0\./, "")
assigns.push(name + " = " + _)
return name
} else {
return _
}
})
})
//---------------args----------------
if (filters) {
args.push(avalon.filters)
Expand Down Expand Up @@ -2571,9 +2586,12 @@
parseExpr(code, scopes, data)
if (data.evaluator && !noregister) {
data.handler = bindingExecutors[data.handlerName || data.type]
data.evaluator.toString = function() {
return data.type + " binding to eval(" + code + ")"
if (data.type === "if") {
console.log(data.evaluator + "")
}
// data.evaluator.toString = function() {
// return data.type + " binding to eval(" + code + ")"
// }
//方便调试
//这里非常重要,我们通过判定视图刷新函数的element是否在DOM树决定
//将它移出订阅者列表
Expand Down
18 changes: 17 additions & 1 deletion avalon.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,7 @@
for (var i = vars.length, prop; prop = vars[--i]; ) {
if (scope.hasOwnProperty(prop)) {
ret.push(prop + prefix + prop)
data.vars.push(prop)
if (data.type === "duplex") {
vars.get = name + "." + prop
}
Expand Down Expand Up @@ -1848,6 +1849,7 @@
names = [],
args = [],
prefix = ""
data.vars = []
//args 是一个对象数组, names 是将要生成的求值函数的参数
scopes = uniqSet(scopes)
for (var i = 0, sn = scopes.length; i < sn; i++) {
Expand All @@ -1861,6 +1863,20 @@
if (!assigns.length && dataType === "duplex") {
return
}
//https://github.com/RubyLouvre/avalon/issues/583
data.vars.forEach(function(v) {
var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig")
code = code.replace(reg, function(_) {
var c = _.charAt(v.length)
if (c === "." || c === "[") {
var name = "var" + String(Math.random()).replace(/^0\./, "")
assigns.push(name + " = " + _)
return name
} else {
return _
}
})
})
//---------------args----------------
if (filters) {
args.push(avalon.filters)
Expand Down Expand Up @@ -1931,7 +1947,7 @@
} catch (e) {
log("debug: parse error," + e.message)
} finally {
vars = textBuffer = names = null //释放内存
vars = textBuffer = names = null //释放内存
}
}

Expand Down

0 comments on commit bfa45a2

Please sign in to comment.