Sha256: d7c802c4c45b47dd8ec6952b220e425d6313f18678e629bae8502cfe614b736f

Contents?: true

Size: 1.29 KB

Versions: 14

Compression:

Stored size: 1.29 KB

Contents

/**
 *  Manages a conditional child VM using the
 *  binding's value as the component ID.
 */
module.exports = {

    bind: function () {

        // track position in DOM with a ref node
        var el       = this.raw = this.el,
            parent   = el.parentNode,
            ref      = this.ref = document.createComment('v-view')
        parent.insertBefore(ref, el)
        parent.removeChild(el)

        // cache original content
        /* jshint boss: true */
        var node,
            frag = this.inner = document.createElement('div')
        while (node = el.firstChild) {
            frag.appendChild(node)
        }

    },

    update: function(value) {

        this.unbind()

        var Ctor  = this.compiler.getOption('components', value)
        if (!Ctor) return

        this.childVM = new Ctor({
            el: this.raw.cloneNode(true),
            parent: this.vm,
            compilerOptions: {
                rawContent: this.inner.cloneNode(true)
            }
        })

        this.el = this.childVM.$el
        if (this.compiler.init) {
            this.ref.parentNode.insertBefore(this.el, this.ref)
        } else {
            this.childVM.$before(this.ref)
        }

    },

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

}

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
fluentd-ui-0.3.8 vendor/assets/javascripts/bower/vue/src/directives/view.js
fluentd-ui-0.3.7 vendor/assets/javascripts/bower/vue/src/directives/view.js
fluentd-ui-0.3.6 vendor/assets/javascripts/bower/vue/src/directives/view.js
fluentd-ui-0.3.5 vendor/assets/javascripts/bower/vue/src/directives/view.js
fluentd-ui-0.3.3 vendor/assets/javascripts/bower/vue/src/directives/view.js
fluentd-ui-0.3.2 vendor/assets/javascripts/bower/vue/src/directives/view.js
fluentd-ui-0.3.1 vendor/assets/javascripts/bower/vue/src/directives/view.js
fluentd-ui-0.3.0 vendor/assets/javascripts/bower/vue/src/directives/view.js
fluentd-ui-0.2.0 vendor/assets/javascripts/bower/vue/src/directives/view.js
fluentd-ui-0.1.4 vendor/assets/javascripts/bower/vue/src/directives/view.js
fluentd-ui-0.1.3 vendor/assets/javascripts/bower/vue/src/directives/view.js
fluentd-ui-0.1.2 vendor/assets/javascripts/bower/vue/src/directives/view.js
fluentd-ui-0.1.1 vendor/assets/javascripts/bower/vue/src/directives/view.js
fluentd-ui-0.1.0 vendor/assets/javascripts/bower/vue/src/directives/view.js