mirror of https://github.com/vuejs/vue.git
				
				
				
			
		
			
				
	
	
		
			36 lines
		
	
	
		
			789 B
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			789 B
		
	
	
	
		
			JavaScript
		
	
	
	
| var _ = require('../util')
 | |
| var objectAgumentations = Object.create(Object.prototype)
 | |
| 
 | |
| /**
 | |
|  * Add a new property to an observed object
 | |
|  * and emits corresponding event
 | |
|  *
 | |
|  * @param {String} key
 | |
|  * @param {*} val
 | |
|  * @public
 | |
|  */
 | |
| 
 | |
| _.define(objectAgumentations, '$add', function (key, val) {
 | |
|   if (this.hasOwnProperty(key)) return
 | |
|   this[key] = val
 | |
|   this.$observer.convert(key, val)
 | |
|   this.$observer.emit('add', key, val)
 | |
| })
 | |
| 
 | |
| /**
 | |
|  * Deletes a property from an observed object
 | |
|  * and emits corresponding event
 | |
|  *
 | |
|  * @param {String} key
 | |
|  * @public
 | |
|  */
 | |
| 
 | |
| _.define(objectAgumentations, '$delete', function (key) {
 | |
|   if (!this.hasOwnProperty(key)) return
 | |
|   // trigger set events
 | |
|   this[key] = undefined
 | |
|   delete this[key]
 | |
|   this.$observer.emit('delete', key)
 | |
| })
 | |
| 
 | |
| module.exports = objectAgumentations |