• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* eslint-disable */
2
3import {
4  Log,
5  hasOwn
6} from '../../utils/index.ts';
7import * as _ from '../../utils/index.ts';
8
9var objProto = Object.prototype;
10
11/**
12 * Add a new property to an observed object and emits corresponding event.
13 * @param {String} key
14 * @param {*} val
15 * @public
16 */
17_.define(
18  objProto,
19  '$add',
20  function $add (key, val) {
21    Log.warn(`'Object.prototype.$add' is not a standard API,`
22      + ` it will be removed in the next version.`);
23    if (hasOwn(this, key)) {
24      return;
25    }
26    var ob = this.__ob__;
27    if (!ob || _.isReserved(key)) {
28      this[key] = val;
29      return;
30    }
31    ob.convert(key, val);
32    ob.notify();
33    if (ob.vms) {
34      var i = ob.vms.length;
35      while (i--) {
36        var vm = ob.vms[i];
37        vm._proxy(key);
38        // vm._digest() // todo
39      }
40    }
41  }
42)
43
44/**
45 * Set a property on an observed object, calling add to ensure the property is observed.
46 * @param {String} key
47 * @param {*} val
48 * @public
49 */
50_.define(
51  objProto,
52  '$set',
53  function $set (key, val) {
54    Log.warn(`"Object.prototype.$set" is not a standard API,`
55      + ` it will be removed in the next version.`);
56    this.$add(key, val);
57    this[key] = val;
58  }
59)
60
61/**
62 * Deletes a property from an observed object and emits corresponding event.
63 * @param {String} key
64 * @public
65 */
66_.define(
67  objProto,
68  '$delete',
69  function $delete (key) {
70    Log.warn(`"Object.prototype.$delete" is not a standard API,`
71      + ` it will be removed in the next version.`);
72    if (!this.hasOwnProperty(key)) {
73      return;
74    }
75    delete this[key];
76    var ob = this.__ob__;
77    if (!ob || _.isReserved(key)) {
78      return;
79    }
80    ob.notify();
81    if (ob.vms) {
82      var i = ob.vms.length;
83      while (i--) {
84        var vm = ob.vms[i];
85        vm._unproxy(key);
86        // vm._digest() // todo
87      }
88    }
89  }
90)
91