Skip to content

Add $asyncComputed status property #45

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

Merged
merged 2 commits into from
Nov 3, 2018

Conversation

michaelzangl
Copy link
Contributor

@michaelzangl michaelzangl commented Sep 18, 2018

This patch is an improved version of #29 and adds a status property to each Vue instance that contains information about it's asyncComputed properties.

If you access $asyncComputed.myAsyncPropName on the instance, you will get an object like this:

{
  // Can be one of updating, success, error
  state: 'updating',
  // A boolean that is true while the property is updating.
  updating: true,
  // The property finished updating wihtout errors (the promise was resolved) and the current value is available.
  success: false,
  // The promise was rejected.
  error: false,
  // The raw error/exception with which the promise was rejected.
  exception: null
  // A function that, when called, forces the property to be re-calculated
  update: function() {...}
}

The boolean properties are redundant, since there already is the state property. But they make implementing loading spinners and error indicators easier.

Use like this:

<div v-if="$asyncComputed.myProperty.updating">
  Please wait, data is loading
</div>
<div v-else-if="$asyncComputed.myProperty.error">
  Error while computing the data: {{ $asyncComputed.myProperty.exception }}
  <button @click="$asyncComputed.myProperty.update()">Retry</button>
</div>
<div v-else>
  Here is your data: {{ myProperty }}
</div>

@gavinhungry wanted to be mentioned.

To test, use:

"dependencies": {
  "vue-async-computed": "fumiX/vue-async-computed#dist",
}

@foxbenjaminfox foxbenjaminfox merged commit b3872c2 into foxbenjaminfox:master Nov 3, 2018
@foxbenjaminfox
Copy link
Owner

Thanks for the PR, this is a good and worthwhile feature.

Everything looks good, so I've merged the PR and published a new minor version of vue-async-computed that includes it, v3.5.0.

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.

2 participants