Skip to content

Commit

Permalink
make sure ractive models get torn down with their owning instance - f…
Browse files Browse the repository at this point in the history
…ixes #3164
  • Loading branch information
evs-chris committed Dec 15, 2017
1 parent 0c8d763 commit 8c1d25e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/model/RootModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export default class RootModel extends Model {
for ( const k in this.computations ) {
this.computations[ k ].teardown();
}
this.ractiveModel && this.ractiveModel.teardown();
}
}
RootModel.prototype.update = noop;
Expand Down
20 changes: 20 additions & 0 deletions tests/browser/components/data-and-mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1710,4 +1710,24 @@ export default function() {

t.htmlEqual( fixture.innerHTML, 'cmp1 foo cmp2 foo' );
});

test( `links to other ractive instances are torn down with components (#3164)`, t => {
const done = t.async();

const cmp = Ractive.extend({
template: '{{@.root.foo}}'
});
const r = new Ractive({
target: fixture,
template: '{{#unless done}}<cmp />{{/unless}}',
components: { cmp },
foo: 'bar'
});

t.htmlEqual( fixture.innerHTML, 'bar' );
r.toggle( 'done' ).then( () => {
t.htmlEqual( fixture.innerHTML, '' );
t.equal( r.viewmodel.ractiveModel.links.length, 0 );
}).then( done, done );
});
}

0 comments on commit 8c1d25e

Please sign in to comment.