Skip to content

Data getters are being invoked on component initialisation  #7280

Closed
@DeyLak

Description

@DeyLak

Version

2.5.11

Reproduction link

https://jsfiddle.net/7gmh5wL8/1/

Steps to reproduce

  • Run JSFiddle snippet
  • Open browser console
  • You'll see a warning from property getter

What is expected?

I expect, that my data and props enumerable properties will not be invoked, without my explicit call for them.

What is actually happening?

Seems, that defineReactive function in /src/core/observer/index.js works that way, that it accepts an object property value, instead of getting it from the getter on demand. Despite the fact, that it uses getOwnPropertyDescriptor to respect user-defined getters and setters.


I faced this problem in a context of lazy-loaded backend entities. I have some redux store selectors, that returns RESTfull models. Some of the models nested properties are wrapped into getters, so I can call them, if needed and trigger a background api request for additional info. Now, all of the getters are invoked immediately and a bunch of requests is sent after initial rendering.

I can do a pull request, to fix this, but may be I do not understand some concept under this behaviour.

Sorry for bad english.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions