var _ = require('../util')
var FragmentFactory = require('../fragment/factory')
var vIf = require('../directives/if')

module.exports = {

  bind: function () {
    var el = this.el
    this.anchor = _.createAnchor('v-partial')
    _.replace(el, this.anchor)
    var id = el.getAttribute('name')
    var tokens = textParser.parse(id)
    if (tokens) {
      // dynamic partial
      this.setupDynamic(tokens)
    } else {
      // static partial
      this.insert(id)
    }
  },

  setupDynamic: function (tokens) {
    var self = this
    var exp = textParser.tokensToExp(tokens)
    this.unwatch = this.vm.$watch(exp, function (value) {
      vIf.remove.call(self)
      self.insert(value)
    }, {
      immediate: true,
      user: false,
      scope: this._scope
    })
  },

  insert: function (id) {
    var partial = _.resolveAsset(this.vm.$options, 'partials', id)
    if (process.env.NODE_ENV !== 'production') {
      _.assertAsset(partial, 'partial', id)
    }
    if (partial) {
      this.factory = new FragmentFactory(this.vm, partial)
      vIf.insert.call(this)
    }
  },

  unbind: function () {
    if (this.frag) this.frag.unlink()
    if (this.unwatch) this.unwatch()
  }
}

@@ -20,16 +20,60 @@
 /util')%0A
+var textParser = require('../parsers/text')%0A
 var Frag

fix partial