Skip to content

$asnyComputed is undefined in computed property when watcher is called first #74

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

Closed
johannes-z opened this issue Mar 20, 2019 · 1 comment · Fixed by #95
Closed

$asnyComputed is undefined in computed property when watcher is called first #74

johannes-z opened this issue Mar 20, 2019 · 1 comment · Fixed by #95

Comments

@johannes-z
Copy link
Contributor

@foxbenjaminfox

AsyncComputed properties are undefined when being used in a computed property, at least in this edge case that I implemented. I made a sandbox repro: https://codesandbox.io/s/m34kn80m9j

After the latest changes, it's still initially undefined, at least when using watchers. Because of this I can't make computed properties depend on the asyncComputed state, e.g. updating.

Here is the code (unimportant stuff was truncated):

App.vue

<template>
  <div id="app">
    Parent: {{ childProp }}
    <ChildComponent ref="child" @update:someProp="childProp = $event;" />
  </div>
</template>

<script>
import ChildComponent from "./Child.vue";
export default {
  components: { ChildComponent },
  data() {
    return {
      childProp: {}
    };
  }
};
</script>

Child.vue

<template>
  <div>
    Child: {{ someProp }} {{ $asyncComputed.posts.updating }}
    <div v-for="(post, index) in posts" :key="index">{{ post }}</div>
  </div>
</template>

<script>
export default {
  watch: {
    someProp: {
      deep: true,
      immediate: true,
      handler(newVal) {
        this.$emit("update:someProp", newVal);
      }
    }
  },
  computed: {
    someProp() {
      console.log(this.$asyncComputed.posts);
      return {
        prop: "value",
        error: this.$asyncComputed.posts.error
      };
    }
  },
  asyncComputed: {
    posts: {
      lazy: true,
      default: () => [],
      async get() {
        return [1, 2];
      }
    }
  }
};
</script>
@aekasitt
Copy link

Anything being worked on this issue?

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