Skip to content

Commit 677378e

Browse files
author
mengxiangxiang
committed
修复多个计算属性不更新的问题
判断应该更新计算属性后,原本会更新依赖属性的版本号,但是这样后面依赖这个属性的计算属性就不会更新了,所以改成更新计算属性自己维护的依赖版本号
1 parent c27e76b commit 677378e

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/vmodel/Computed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export var Computed = (function(_super) {
7575
for (var i in this.deps) {
7676
if (this.deps[i].version !== this.depsVersion[i]) {
7777
toComputed = true
78-
this.deps[i].version = this.depsVersion[i]
78+
this.depsVersion[i] = this.deps[i].version
7979
}
8080
}
8181
return toComputed

test/vmodel/compact.spec.js

+38
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,44 @@ describe('Computed', function () {
291291
expect(vm.c).toBe(25)
292292
delete avalon.vmodels.computed01
293293
})
294+
295+
it('test2', function (done) {
296+
var body = document.body
297+
var div = document.createElement('div')
298+
div.innerHTML = heredoc(function() {
299+
/*
300+
<div :controller="computed02">
301+
<div>{{@b}}</div>
302+
<div>{{@c}}</div>
303+
</div>
304+
*/
305+
})
306+
body.appendChild(div)
307+
308+
var vm = avalon.define({
309+
$id: 'computed02',
310+
$computed: {
311+
b: function(){
312+
return this.a + 1
313+
},
314+
c: function(){
315+
return this.a + 2
316+
}
317+
},
318+
a: 1
319+
})
320+
avalon.scan(div)
321+
322+
setTimeout(function () {
323+
vm.a = 10
324+
expect(vm.b).toBe(11)
325+
expect(vm.c).toBe(12)
326+
327+
body.removeChild(div)
328+
delete avalon.vmodels.computed02
329+
done()
330+
}, 500);
331+
})
294332
})
295333

296334
describe('Action', function () {

0 commit comments

Comments
 (0)