Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support symbols as keys in observed objects #10741

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open

feat: support symbols as keys in observed objects #10741

wants to merge 4 commits into from

Conversation

xx1124961758
Copy link

@xx1124961758 xx1124961758 commented Oct 21, 2019

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

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

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

  • Yes
  • No

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

The PR fulfills these requirements:

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:

Fixed when the key of the object is of symbol type, it does not work.
@posva posva changed the title fix #10734[, ##10734] feat: support symbols as keys in observed objects Oct 21, 2019
xx1124961758 added a commit to xx1124961758/vue that referenced this pull request Oct 22, 2019
feat: support symbols as keys in observed objects  fix vuejs#10741[, vuejs#10741]
@Tipwheal
Copy link

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.

@xx1124961758
Copy link
Author

xx1124961758 commented Oct 23, 2019

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
Copy link

guda-art commented Apr 1, 2023

你的意思是, 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
Copy link

guda-art commented Apr 1, 2023

还是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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants