Sha256: 4862b49b11593d958574d32a48657357c2c1fb88a20e93f927f50ab9fcc43b1d

Contents?: true

Size: 1.46 KB

Versions: 14

Compression:

Stored size: 1.46 KB

Contents

var utils    = require('../utils')

/**
 *  Manages a conditional child VM
 */
module.exports = {

    bind: function () {
        
        this.parent = this.el.parentNode
        this.ref    = document.createComment('vue-if')
        this.Ctor   = this.compiler.resolveComponent(this.el)

        // insert ref
        this.parent.insertBefore(this.ref, this.el)
        this.parent.removeChild(this.el)

        if (utils.attr(this.el, 'view')) {
            utils.warn(
                'Conflict: v-if cannot be used together with v-view. ' +
                'Just set v-view\'s binding value to empty string to empty it.'
            )
        }
        if (utils.attr(this.el, 'repeat')) {
            utils.warn(
                'Conflict: v-if cannot be used together with v-repeat. ' +
                'Use `v-show` or the `filterBy` filter instead.'
            )
        }
    },

    update: function (value) {

        if (!value) {
            this.unbind()
        } else if (!this.childVM) {
            this.childVM = new this.Ctor({
                el: this.el.cloneNode(true),
                parent: this.vm
            })
            if (this.compiler.init) {
                this.parent.insertBefore(this.childVM.$el, this.ref)
            } else {
                this.childVM.$before(this.ref)
            }
        }
        
    },

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

Version data entries

14 entries across 14 versions & 1 rubygems

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