Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 49205c5

Browse files
committed
1 parent fdffc23 commit 49205c5

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

demo/demo.bisheng.tmp.html

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
<script id="hello" type="template">
3232
{{#each list}}
33-
<p>{{array}}</p>
33+
<input value="{{scaleValue}}">
3434
{{/each}}
3535
</script>
3636

@@ -45,22 +45,35 @@
4545
// BS.auto(true)
4646
var tpl = $('#hello').html()
4747
data = {
48-
list: [{
49-
array: [0]
48+
"list": [{
49+
"siteId": 1481,
50+
"catId": 7,
51+
"scaleMin": 0.5,
52+
"scaleMax": 50.0,
53+
"scaleOldValue": 0,
54+
"scaleValue": 7.0,
55+
"catName": "数码、电脑",
56+
"offerCount": 16
5057
}, {
51-
array: [0, 1]
52-
}, {
53-
array: [0, 1, 2]
58+
"siteId": 1481,
59+
"catId": 68,
60+
"scaleMin": 0.5,
61+
"scaleMax": 50.0,
62+
"scaleOldValue": 0,
63+
"scaleValue": 2.0,
64+
"catName": "包装",
65+
"offerCount": 1
5466
}]
55-
}
67+
}
5668
bs = BS.bind(data, tpl, function(content){
5769
$('#demo').append(content)
5870
})
5971
task = function(){
60-
data.list[1].array.sort(function(a, b) {
61-
return b - a
62-
})
72+
6373
}
74+
BS.watch(data, 'list', function(changes){
75+
console.log(changes)
76+
})
6477
setTimeout(function(){
6578
// data.radioChecked1 = false
6679
// data.radioChecked2 = true

dist/bisheng.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ define(
11951195
}
11961196

11971197
updateValue(data, path, event.target)
1198-
if (!Loop.auto()) Loop.letMeSee(data, tpl)
1198+
if (!Loop.auto()) Loop.letMeSee(data /*, tpl*/ )
11991199
})
12001200
})
12011201

@@ -1230,7 +1230,7 @@ define(
12301230
.trigger('change.bisheng', firing = true)
12311231
}
12321232
updateChecked(data, path, event.target)
1233-
if (!Loop.auto()) Loop.letMeSee(data, tpl)
1233+
if (!Loop.auto()) Loop.letMeSee(data /*, tpl*/ )
12341234
})
12351235
})
12361236
}

src/brix/bisheng/scan.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ define(
212212
}
213213

214214
updateValue(data, path, event.target)
215-
if (!Loop.auto()) Loop.letMeSee(data, tpl)
215+
if (!Loop.auto()) Loop.letMeSee(data /*, tpl*/ )
216216
})
217217
})
218218

@@ -247,7 +247,7 @@ define(
247247
.trigger('change.bisheng', firing = true)
248248
}
249249
updateChecked(data, path, event.target)
250-
if (!Loop.auto()) Loop.letMeSee(data, tpl)
250+
if (!Loop.auto()) Loop.letMeSee(data /*, tpl*/ )
251251
})
252252
})
253253
}

test/test.bisheng.watch.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,23 @@ describe('Watch', function() {
8282
doBiShengWatch(data, 'foo', task, expected, done)
8383
})
8484

85+
it('BiSheng.watch(data, property, fn(change)), nested', function(done) {
86+
var data = {
87+
list: [{
88+
foo: {}
89+
}]
90+
}
91+
var task = function() {
92+
data.list[0].foo.bar = 123
93+
}
94+
var expected = {
95+
type: 'add',
96+
path: ['list', '0', 'foo', 'bar'],
97+
value: 123
98+
}
99+
doBiShengWatch(data, 'list', task, expected, done)
100+
})
101+
85102
/*
86103
var data = {}
87104
BiSheng.watch(data, ['a', 'b', 'c'], function(change) {

0 commit comments

Comments
 (0)