Skip to content

Commit

Permalink
Merge pull request #448 from sveltejs/gh-441
Browse files Browse the repository at this point in the history
reverse pre and post to fix deferred observers
  • Loading branch information
Rich-Harris authored Apr 8, 2017
2 parents 6802f43 + 7219202 commit 35113bd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/shared/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
4 changes: 2 additions & 2 deletions test/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions test/generator/samples/observe-deferred/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default {
'skip-ssr': true,

data: {
value: 'hello!'
},

html: `
<p>hello!</p>
<p>hello!</p>
`,

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

component.destroy();
}
};
14 changes: 14 additions & 0 deletions test/generator/samples/observe-deferred/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p ref:a>{{value}}</p>
<p ref:b></p>

<script>
export default {
oncreate () {
this.observe( 'value', () => {
this.refs.b.textContent = this.refs.a.textContent;
}, {
defer: true
});
}
};
</script>

0 comments on commit 35113bd

Please sign in to comment.