From 72192024719d6d2a6b6228f711cc9fe73d212032 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 4 Apr 2017 11:51:30 -0400 Subject: [PATCH 1/2] reverse pre and post to fix deferrerd observers (fixes #441) --- src/shared/methods.js | 2 +- test/generator/index.js | 4 ++-- .../samples/observe-deferred/_config.js | 22 +++++++++++++++++++ .../samples/observe-deferred/main.html | 14 ++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 test/generator/samples/observe-deferred/_config.js create mode 100644 test/generator/samples/observe-deferred/main.html diff --git a/src/shared/methods.js b/src/shared/methods.js index 395420767d..2db30991ea 100644 --- a/src/shared/methods.js +++ b/src/shared/methods.js @@ -12,7 +12,7 @@ export function fire ( eventName, data ) { } export function observe ( key, callback, options ) { - var group = ( options && options.defer ) ? this._observers.pre : this._observers.post; + var group = ( options && options.defer ) ? this._observers.post : this._observers.pre; ( group[ key ] || ( group[ key ] = [] ) ).push( callback ); diff --git a/test/generator/index.js b/test/generator/index.js index 6ca442623b..ccce7e259e 100644 --- a/test/generator/index.js +++ b/test/generator/index.js @@ -135,14 +135,14 @@ describe( 'generate', () => { assert.htmlEqual( target.innerHTML, config.html ); } + Object.assign = Object_assign; + if ( config.test ) { config.test( assert, component, target, window ); } else { component.destroy(); assert.equal( target.innerHTML, '' ); } - - Object.assign = Object_assign; }) .catch( err => { Object.assign = Object_assign; diff --git a/test/generator/samples/observe-deferred/_config.js b/test/generator/samples/observe-deferred/_config.js new file mode 100644 index 0000000000..8ccca0d2ab --- /dev/null +++ b/test/generator/samples/observe-deferred/_config.js @@ -0,0 +1,22 @@ +export default { + 'skip-ssr': true, + + data: { + value: 'hello!' + }, + + html: ` +

hello!

+

hello!

+ `, + + test ( assert, component, target ) { + component.set({ value: 'goodbye!' }); + assert.htmlEqual( target.innerHTML, ` +

goodbye!

+

goodbye!

+ ` ); + + component.destroy(); + } +}; diff --git a/test/generator/samples/observe-deferred/main.html b/test/generator/samples/observe-deferred/main.html new file mode 100644 index 0000000000..365d427f4d --- /dev/null +++ b/test/generator/samples/observe-deferred/main.html @@ -0,0 +1,14 @@ +

{{value}}

+

+ + \ No newline at end of file From 3ed4dc68eea2c6c97201a655cdfa7edbbff4642d Mon Sep 17 00:00:00 2001 From: Taylor Zane Glaeser Date: Tue, 4 Apr 2017 22:41:49 -0500 Subject: [PATCH 2/2] Fixes #452. Fixed an issue that caused setting `computed` to an empty object to prevent the component from compiling. --- src/generators/dom/index.js | 2 +- test/generator/samples/computed-empty/_config.js | 8 ++++++++ test/generator/samples/computed-empty/main.html | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/generator/samples/computed-empty/_config.js create mode 100644 test/generator/samples/computed-empty/main.html diff --git a/src/generators/dom/index.js b/src/generators/dom/index.js index 4f829776fd..ee08ab4394 100644 --- a/src/generators/dom/index.js +++ b/src/generators/dom/index.js @@ -302,7 +302,7 @@ export default function dom ( parsed, source, options ) { constructorBlock.addBlock( generator.builders.metaBindings ); } - if ( templateProperties.computed ) { + if ( computations.length ) { constructorBlock.addLine( `${generator.alias( 'recompute' )}( this._state, this._state, {}, true );` ); diff --git a/test/generator/samples/computed-empty/_config.js b/test/generator/samples/computed-empty/_config.js new file mode 100644 index 0000000000..226be4cffe --- /dev/null +++ b/test/generator/samples/computed-empty/_config.js @@ -0,0 +1,8 @@ +export default { + html: '
empty
', + test ( assert, component, target ) { + assert.equal( component.get( 'created' ), true ); + assert.equal( target.innerHTML, '
empty
' ); + component.destroy(); + } +}; diff --git a/test/generator/samples/computed-empty/main.html b/test/generator/samples/computed-empty/main.html new file mode 100644 index 0000000000..9dd0e10923 --- /dev/null +++ b/test/generator/samples/computed-empty/main.html @@ -0,0 +1,14 @@ +
empty
+