Sha256: 2f7f243672b515a4b18f85e93cfbd0d41224d8ae4d7731fd1e928f59e5c4e9e1

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

var _ = require('../util')
var objProto = Object.prototype

/**
 * Add a new property to an observed object
 * and emits corresponding event
 *
 * @param {String} key
 * @param {*} val
 * @public
 */

_.define(
  objProto,
  '$add',
  function $add (key, val) {
    var ob = this.__ob__
    if (!ob) {
      this[key] = val
      return
    }
    if (_.isReserved(key)) {
      _.warn('Refused to $add reserved key: ' + key)
      return
    }
    if (this.hasOwnProperty(key)) return
    ob.convert(key, val)
    if (ob.vms) {
      var i = ob.vms.length
      while (i--) {
        var vm = ob.vms[i]
        vm._proxy(key)
        vm._digest()
      }
    } else {
      ob.notify()
    }
  }
)

/**
 * Deletes a property from an observed object
 * and emits corresponding event
 *
 * @param {String} key
 * @public
 */

_.define(
  objProto,
  '$delete',
  function $delete (key) {
    var ob = this.__ob__
    if (!ob) {
      delete this[key]
      return
    }
    if (_.isReserved(key)) {
      _.warn('Refused to $add reserved key: ' + key)
      return
    }
    if (!this.hasOwnProperty(key)) return
    delete this[key]
    if (ob.vms) {
      var i = ob.vms.length
      while (i--) {
        var vm = ob.vms[i]
        vm._unproxy(key)
        vm._digest()
      }
    } else {
      ob.notify()
    }
  }
)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluentd-ui-0.3.9 vendor/assets/javascripts/bower/vue/src/observer/object.js