Subscribe on changes!

Two problems of Proxy

avatar
Sep 11th 2020

Version

3.0.0-rc.10

Reproduction link

https://codepen.io/wgjas2/pen/VwaxpNX

Steps to reproduce

Problem 1:

When some library use WeakMap in class like:

  • outer class:
const privates = new WeakMap()
  • class constructor:
privates.set(this, ...)  
  • class method:
const weakobj = privates.get(this)  

now weakobj is value undefined, because that this in method is Proxy(this) ...... then Proxy(this) !== this,so WeakMap not working.

Problem 2:

When use some library (like Cesium&EarthSDK、Three.js) can create huge data in object, Proxy(obj) cause 2x~4x memory use

What is expected?

have a solution to make object not to Proxy

What is actually happening?

  1. Proxy not compatible WeakMap
  2. Huge memory use
avatar
Sep 11th 2020
  1. Proxies will always have different identity from its target. The best practice is to never keep a reference of the raw object and only work with the reactive version of it.

  2. https://v3.vuejs.org/api/basic-reactivity.html#markraw