all files / lib/ subtag.js

100% Statements 12/12
100% Branches 4/4
100% Functions 4/4
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21                   
 
riot.tag('subtag', '<div riot-tag="{opts.tag}"></div>', function(opts) {this.prevtag = null;
 
this.on('mount', function() {
  this.prevtag = opts.tag;
  return this.mountedTag = riot.mount(this.root.querySelector('div'), opts.tag, opts)[0];
});
 
this.on('update', function() {
  if (this.prevtag && this.prevtag !== opts.tag) {
    this.prevtag = opts.tag;
    this.mountedTag.unmount(true);
    return this.mountedTag = riot.mount(this.root.querySelector('div'), opts.tag, opts)[0];
  }
});
 
this.on('unmount', function() {
  return this.mountedTag.unmount(true);
});
 
});