diff --git a/src/js-framework/lib/__test__/assets/created.input b/src/js-framework/lib/__test__/assets/created.input new file mode 100644 index 0000000000..3591bb5b48 --- /dev/null +++ b/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" +}) \ No newline at end of file diff --git a/src/js-framework/lib/__test__/assets/created.output b/src/js-framework/lib/__test__/assets/created.output new file mode 100644 index 0000000000..39c15f3254 --- /dev/null +++ b/src/js-framework/lib/__test__/assets/created.output @@ -0,0 +1,11 @@ +{ + "children": [ + { + "attr": { + "value": "1" + }, + "type": "text" + } + ], + "type": "container" +} \ No newline at end of file diff --git a/src/js-framework/lib/__test__/assets/ready.input b/src/js-framework/lib/__test__/assets/ready.input new file mode 100644 index 0000000000..a7704f99c5 --- /dev/null +++ b/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" +}) \ No newline at end of file diff --git a/src/js-framework/lib/__test__/assets/ready.output b/src/js-framework/lib/__test__/assets/ready.output new file mode 100644 index 0000000000..39c15f3254 --- /dev/null +++ b/src/js-framework/lib/__test__/assets/ready.output @@ -0,0 +1,11 @@ +{ + "children": [ + { + "attr": { + "value": "1" + }, + "type": "text" + } + ], + "type": "container" +} \ No newline at end of file diff --git a/src/js-framework/lib/__test__/test.js b/src/js-framework/lib/__test__/test.js index 34f464236a..ca45ed2c44 100644 --- a/src/js-framework/lib/__test__/test.js +++ b/src/js-framework/lib/__test__/test.js @@ -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] + }) }) diff --git a/src/js-framework/lib/app/ctrl.js b/src/js-framework/lib/app/ctrl.js index 88203a5412..18263928ae 100644 --- a/src/js-framework/lib/app/ctrl.js +++ b/src/js-framework/lib/app/ctrl.js @@ -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() }