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

"lazy: true" fails to stop updates #122

Open
cepm-nate opened this issue Jan 2, 2023 · 1 comment
Open

"lazy: true" fails to stop updates #122

cepm-nate opened this issue Jan 2, 2023 · 1 comment

Comments

@cepm-nate
Copy link

I think this line is to blame:

if (isLazyActive(this, key)) {

Logic goes like this:

  • "isComputedLazy": "Does the asyncComputed property have the 'lazy' property?
  • "isLazyActive": "Is the [lazy] property set to true?
  • If both above are true, then it does return nonLazy.call(this).

Note the last step. That seems backwards. Shouldn't it be return silentGetLazy(this, key), if this is a [lazy] property, and set to active?

In my .vue file I have a simple asyncComputed property with lazy: true, and a console.log within it's getter. The console.log fires whenever a referenced property updates, even though lazy is set to true.

    CallRecordingInfo: {
      default() { return false; },
      lazy: false,
      get() {
        if (!this.Call || !this.Call.Call) return Promise.resolve(false);
        console.log('Updating CalLRecordingInfo', this);
        return api.calls().getRecordingUrl(
          this.UUID,
          this.HQCo,
          this.Call.Call,
        ).catch(() => Promise.resolve(false));
      },
    },

When looking at the console.log output for this, it shows async_computed$lazy_active$CallRecordingInfo: true and async_computed$lazy_data$CallRecordingInfo: Object.

Am I missing something?

@cepm-nate
Copy link
Author

I forked the repo and swapped the results of that IF statement to reverse them. This accomplished two things:

  • Correctly only called the getter when I called .update()
  • Weirdly did NOT save the results into async_computed$lazy_data$CallRecordingInfo when resolved.

Rather than mess around and set async_computed$lazy_data$CallRecordingInfo manually each time, I figured I'd run clean and swap back to a normal data() property and update it manually.

But I'm still curious: Am I using lazy: true correctly in the code above? Is my expectation correct that lazy getters SHOULD NOT FIRE when referenced properties (this.Call in the above example) change?

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

No branches or pull requests

1 participant