var _ = require('../util')
var templateParser = require('../parse/template')

module.exports = {

  bind: function () {
    var el = this.el
    if (!el.__vue__) {
      this.ref = document.createComment('v-if')
      _.replace(el, this.ref)
      this.inserted = false
      if (el.tagName === 'TEMPLATE') {
        this.el = templateParser.parse(el)
      }
    } else {
      this.invalid = true
      _.warn(
        'v-if="' + this.expression + '" cannot be ' +
        'used on an already mounted instance.'
      )
    }
  },

  update: function (value) {
    if (this.invalid) return
    if (value) {
      if (!this.inserted) {
        if (!this.childVM) {
          this.build()
        }
        this.childVM.$before(this.ref)
        this.inserted = true
      }
    } else {
      if (this.inserted) {
        this.childVM.$remove()
        this.inserted = false
      }
    }
  },

  build: function () {
    this.childVM = this.vm.$addChild({
      el: this.el,
      parent: this.vm,
      _anonymous: true
    })
  },

  unbind: function () {
    if (this.childVM) {
      this.childVM.$destroy()
    }
  }

}
@@ -678,14 +678,132 @@
 his.
-build(
+childVM = this.vm.$addChild(%7B%0A            el: this.el,%0A            parent: this.vm,%0A            _anonymous: true%0A          %7D
 )%0A  
@@ -1011,148 +1011,8 @@
 %7D,%0A%0A
-  build: function () %7B%0A    this.childVM = this.vm.$addChild(%7B%0A      el: this.el,%0A      parent: this.vm,%0A      _anonymous: true%0A    %7D)%0A  %7D,%0A%0A
   un

simplify v-if