Skip to content

Commit

Permalink
* [jsfm] fix change data when ready
Browse files Browse the repository at this point in the history
  • Loading branch information
terrykingcha committed May 4, 2016
1 parent 278fca6 commit 0a1aa5d
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/js-framework/lib/__test__/assets/created.input
@@ -0,0 +1,38 @@
define('@weex-component/created', function(require, exports, module) {

;
module.exports = {
data: function() {
return {
text: '',
}
},
created: function() {
this.text = '1'
}
}


;
module.exports.style = {}

;
module.exports.template = {
"type": "container",
"children": [{
"type": "text",
"attr": {
"value": function() {
return this.text
}
}
}]
}

;
})

// require module
bootstrap('@weex-component/created', {
"transformerVersion": "0.3.1"
})
11 changes: 11 additions & 0 deletions src/js-framework/lib/__test__/assets/created.output
@@ -0,0 +1,11 @@
{
"children": [
{
"attr": {
"value": "1"
},
"type": "text"
}
],
"type": "container"
}
38 changes: 38 additions & 0 deletions src/js-framework/lib/__test__/assets/ready.input
@@ -0,0 +1,38 @@
define('@weex-component/created', function(require, exports, module) {

;
module.exports = {
data: function() {
return {
text: '',
}
},
ready: function() {
this.text = '1'
}
}


;
module.exports.style = {}

;
module.exports.template = {
"type": "container",
"children": [{
"type": "text",
"attr": {
"value": function() {
return this.text
}
}
}]
}

;
})

// require module
bootstrap('@weex-component/created', {
"transformerVersion": "0.3.1"
})
11 changes: 11 additions & 0 deletions src/js-framework/lib/__test__/assets/ready.output
@@ -0,0 +1,11 @@
{
"children": [
{
"attr": {
"value": "1"
},
"type": "text"
}
],
"type": "container"
}
32 changes: 32 additions & 0 deletions src/js-framework/lib/__test__/test.js
Expand Up @@ -744,4 +744,36 @@ describe('test input and output', function () {
framework.destroyInstance(name)
delete allDocs[name]
})

it('change data when created', function () {
var name = 'created'
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('change data when ready', function () {
var name = 'ready'
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]
})
})
1 change: 1 addition & 0 deletions src/js-framework/lib/app/ctrl.js
Expand Up @@ -23,6 +23,7 @@ export function init(code, data) {
const define = bind(this.define, this)
const bootstrap = (name, config, _data) => {
result = this.bootstrap(name, config, _data || data)
this.updateActions()
this.doc.listener.createFinish()
this.doc.close()
}
Expand Down

0 comments on commit 0a1aa5d

Please sign in to comment.