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

default as function #9

Closed
mdreizin opened this issue Jan 18, 2017 · 3 comments
Closed

default as function #9

mdreizin opened this issue Jan 18, 2017 · 3 comments

Comments

@mdreizin
Copy link

Hello,

It would be nice to use function for getting default value:

new Vue({
  data: {
    postId: 1
  },
  asyncComputed: {
    blogPostContent: {
      get () {
        return Vue.http.get('/post/' + this.postId)
          .then(response => response.data.postContent)
       },
       default: () => `Loading post ${this.postId}...`
    }
  }
}
@foxbenjaminfox
Copy link
Owner

The main issue with this is that currently, the default values are set in the beforeCreated hook, so in your example it would be called before this.postId is set. (Putting aside the slight error in the example you gave: The arrow function has a lexically scoped this, so this.postId wouldn't refer to what you'd want it to regardless. But that's a separate matter.)

So, what are the options? Well, I could move the computation of the defaults to the created hook instead. That would mostly work, but it would technically be a breaking change. I could move only function defaults to the created hook, but that would be confusing.

Unless I can think of a better idea, I'll probably choose the first option, which would necessitate a major version bump, but that's not the end of the world. Still, I'd rather avoid breaking backwards compatibility needlessly, even if almost no one is relying on the defaults already being defined before their data function is called.

@foxbenjaminfox
Copy link
Owner

foxbenjaminfox commented Jan 20, 2017

I've just released a new version including this feature.

Thank you for the idea! This certainly does seem like a feature that could be quite handy to have available.

@mdreizin
Copy link
Author

@foxbenjaminfox Thank you for quick implementation of this feature ;)

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

2 participants