Skip to content

Commit

Permalink
* [jsfm] fix when the key of trackby is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
terrykingcha committed May 6, 2016
1 parent 9a1ae1a commit efa5070
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 1 deletion.
59 changes: 59 additions & 0 deletions src/js-framework/lib/__test__/assets/repeat-watch.input
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
define('@weex-component/04f1048c50eca3454bc70de93d3213d4', function(require, exports, module) {

;
module.exports = {
data: function() {
return {
list: [{
text: 1
}, {
text: 2
}],
more: [{
text: 3
}]
}
},
ready: function() {
for (var i = 0; i < this.more.length; i++) {
this.list.push(this.more[i]);
}
this._app.updateActions()
}

}


;
module.exports.style = {}

;
module.exports.template = {
"type": "list",
"children": [{
"type": "cell",
"append": "tree",
"repeat": function() {
return this.list
},
"children": [{
"type": "text",
"style": {
"height": 600
},
"attr": {
"value": function() {
return this.text
}
}
}]
}]
}

;
})

// require module
bootstrap('@weex-component/04f1048c50eca3454bc70de93d3213d4', {
"transformerVersion": "0.3.1"
})
46 changes: 46 additions & 0 deletions src/js-framework/lib/__test__/assets/repeat-watch.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"type": "list",
"children": [{
"type": "cell",
"attr": {
"append": "tree"
},
"children": [{
"type": "text",
"attr": {
"value": 1
},
"style": {
"height": 600
}
}]
}, {
"type": "cell",
"attr": {
"append": "tree"
},
"children": [{
"type": "text",
"attr": {
"value": 2
},
"style": {
"height": 600
}
}]
}, {
"type": "cell",
"attr": {
"append": "tree"
},
"children": [{
"type": "text",
"attr": {
"value": 3
},
"style": {
"height": 600
}
}]
}]
}
16 changes: 16 additions & 0 deletions src/js-framework/lib/__test__/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,22 @@ describe('test input and output', function () {
delete allDocs[name]
})

it('repeat-watch case', function () {
var name = 'repeat-watch'
var inputCode = readInput(name)
var outputCode = readOutput(name)
var doc = new Document(name)
allDocs[name] = doc

framework.createInstance(name, inputCode)
var expected = eval('(' + outputCode + ')')
var actual = doc.toJSON()
expect(actual).eql(expected)

framework.destroyInstance(name)
delete allDocs[name]
})

it('if-refresh case', function () {
var name = 'if-refresh'
var inputCode = readInput(name)
Expand Down
3 changes: 2 additions & 1 deletion src/js-framework/lib/vm/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ export function _bindRepeat(target, fragBlock, info) {
const reusedMap = {}
data.forEach((item, index) => {
const key = trackBy ? item[trackBy] : index
if (!key) {
/* istanbul ignore if */
if (key == null || key === '') {
return
}
trackMap[key] = item
Expand Down

0 comments on commit efa5070

Please sign in to comment.