Skip to content

Commit

Permalink
fixed case when no tag is set
Browse files Browse the repository at this point in the history
  • Loading branch information
crisward committed Jan 26, 2016
1 parent 5782e97 commit 8276887
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/subtag.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
riot.tag('subtag', '<div riot-tag="{opts.tag}"></div>', function(opts) {this.prevtag = null;

this.on('mount', function() {
if (!opts.tag) {
return;
}
this.prevtag = opts.tag;
return this.mountedTag = riot.mount(this.root.querySelector('div'), opts.tag, opts)[0];
});
Expand All @@ -15,7 +18,9 @@ this.on('update', function() {
});

this.on('unmount', function() {
return this.mountedTag.unmount(true);
if (this.mountedTag) {
return this.mountedTag.unmount(true);
}
});

});
3 changes: 2 additions & 1 deletion src/subtag.tag
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ subtag
@prevtag = null

@on 'mount',->
return if !opts.tag
@prevtag = opts.tag
@mountedTag = riot.mount(@root.querySelector('div'),opts.tag,opts)[0]

Expand All @@ -15,4 +16,4 @@ subtag
@mountedTag = riot.mount(@root.querySelector('div'),opts.tag,opts)[0]

@on 'unmount',->
@mountedTag.unmount(true)
@mountedTag.unmount(true) if @mountedTag
5 changes: 5 additions & 0 deletions test/subtag.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ describe "subtag",->
opts = {tag:'tag2'}
@tag = riot.mount(@domnode,'subtag',opts)[0]
expect(window.hasunmounted).to.be.true

it "shouldn't go mental if no tag is set",->
opts = {}
@tag = riot.mount(@domnode,'subtag',opts)[0]

0 comments on commit 8276887

Please sign in to comment.