vue icon indicating copy to clipboard operation
vue copied to clipboard

feat: support symbols as keys in observed objects

Open xx1124961758 opened this issue 5 years ago • 4 comments

What kind of change does this PR introduce? (check at least one)

  • [ ] Bugfix
  • [x] Feature
  • [ ] Code style update
  • [ ] Refactor
  • [ ] Build-related changes
  • [ ] Other, please describe:

Does this PR introduce a breaking change? (check one)

  • [ ] Yes
  • [x] No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

  • [x] It's submitted to the dev branch for v2.x (or to a previous version branch), not the master branch
  • [x] When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)
  • [ ] All tests are passing: https://github.com/vuejs/vue/blob/dev/.github/CONTRIBUTING.md#development-setup
  • [ ] New/updated tests are included

If adding a new feature, the PR's description includes:

  • [ ] A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

xx1124961758 avatar Oct 21 '19 13:10 xx1124961758

Take care about methods like initData that use Object.keys to make attributes directly declared in data() reactive, there're many Object.keys calls in the code, ensure that this feature will work properly in mixins, extends or any other places where merging data and so on. The provide/inject option supports symbols by using Reflect.ownKeys and there's a function named hasSymbol in util to check whether symbol and Reflect are available in runtime environment. Also, be aware that the type of param key in defineReactive is string, not string | symbol.

Tipwheal avatar Oct 23 '19 00:10 Tipwheal

lable in runtime environment. Also, be aware that the type of param key in defineReactive is string, not string | symbol.

Symbols are not currently supported by Flow。Reflect.ownkeys returns all the properties on the object, including those that cannot be enumerated. On the other hand, if there is an enumerable "__ob__" attribute on the responsive object, the stack will overflow.

yes, ensure that this feature will work properly everywhere, those places also need to be dealt with.

xx1124961758 avatar Oct 23 '19 04:10 xx1124961758

你的意思是, vue2在对data中的对象进行响应式处理的时候, 并不会处理key为symbol的属性. 但是用$set可以解决这个问题

lable in runtime environment. Also, be aware that the type of param key in defineReactive is string, not string | symbol.

Symbols are not currently supported by Flow。Reflect.ownkeys returns all the properties on the object, including those that cannot be enumerated. On the other hand, if there is an enumerable "ob" attribute on the responsive object, the stack will overflow.

yes, ensure that this feature will work properly everywhere, those places also need to be dealt with.

guda-art avatar Apr 01 '23 05:04 guda-art

还是vue3牛逼啊, 虽然我用$set可以让一个对象中symbol类型的key响应, 但是如果data里面定义的是一个数组, 数组的元素是对象, 对象有symbol类型的key呢, 又该怎么办

lable in runtime environment. Also, be aware that the type of param key in defineReactive is string, not string | symbol.

Symbols are not currently supported by Flow。Reflect.ownkeys returns all the properties on the object, including those that cannot be enumerated. On the other hand, if there is an enumerable "ob" attribute on the responsive object, the stack will overflow.

yes, ensure that this feature will work properly everywhere, those places also need to be dealt with.

guda-art avatar Apr 01 '23 05:04 guda-art