'use strict';

/* create.js
 * Create new tree components through RPV lib.
 */

let create = module.exports = function(constructor, prototype){
  let Component = function(){
    // jshint ignore: start
    if (!new.target) return new Component(...arguments);
    // jshint ignore: end

    this.tags = [];
    constructor.apply(this, arguments);
  };

  Component.prototype = prototype;

  Component.prototype.has = function(item){
    return !!~this.tags.indexOf(item);
  };

  Component.prototype.set = function(){
    this.tags.push(...arguments);
    return this;
  };

  Component.prototype.unset = function(items){
    items = Array.isArray(items) ? items : [items];
    this.tags = this.tags.filter(x => items.indexOf(x) !== -1);
    return this;
  };

  Component.prototype.replace = function(item){
    if (this.parent)
      throw new Error('No reference to parent.  See "no ref" on the RPV wiki.');
  };

  return Component;
};

'use strict';

/* create.js
 * Create new tree components through RPV lib.
 */

let create = module.exports = function(constructor, prototype){
  let Component = function(){
    // jshint ignore: start
    if (!new.target) return new Component(...arguments);
    // jshint ignore: end

    this.tags = [];
    constructor.apply(this, arguments);
  };

  Component.prototype = prototype;

  Component.prototype.has = function(item){
    return !!~this.tags.indexOf(item);
  };

  Component.prototype.set = function(){
    this.tags.push(...arguments);
    return this;
  };

  Component.prototype.unset = function(items){
    items = Array.isArray(items) ? items : [items];
    this.tags = this.tags.filter(x => items.indexOf(x) !== -1);
    return this;
  };

  Component.prototype.replace = function(item){
    if (this.parent)
      throw new Error('No reference to parent.  See "no ref" on the RPV wiki.');

    this.parent.items.splice(this.index, 1, item);
  };

  return Component;
};

Add replacing / removal