question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature request] Use data properties as defaults

See original GitHub issue

I know that we can define defaults using the following syntax:

{
  asyncComputed: {
    item: {
      get() {
        // Do something asynchronous
      },
      default: [], // default value
    },
  },
};

But it would be great if we could use data to define defaults as follows:

{
  data: () => ({
    item: [], // default value
  }),
  asyncComputed: {
    item() {
      // Do something asynchronous
    },
  },
};

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
Coreusacommented, Dec 5, 2018

AsyncComputed is an enhancement (convenience implementation) of Vue’s computed. These are not defined as component data, but defined when they’re created. It follows that AsyncComputed should behave the same way. If one needs default values, use AsyncComputed’s own default:

Computed

computed: {
  fullName: {
    // getter
    get: function () {
      return this.firstName + ' ' + this.lastName
    },
    // setter
    set: function (newValue) {
      var names = newValue.split(' ')
      this.firstName = names[0]
      this.lastName = names[names.length - 1]
    }
  }
}

AsyncComputed

  asyncComputed: {
    blogPostContent: {
      get () {
        return Vue.http.get('/post/' + this.postId)
          .then(response => response.data.postContent)
       },
       // The computed proporty `blogPostContent` will have 
       // the value 'Loading...' until the first time the promise
       // returned from the `get` function resolves.
       default: 'Loading...'
    }
  }
1reaction
michaelzanglcommented, Nov 4, 2018

This is not really the vue way to do it.

Vue defines properties on the instance as sort of aliases of either pops, data or computed. So the vue way is what asyncComputed is doing currently: Add new properties to the instance (and not transform data properties). Currently, no conflict checking is done between async computed properties and data properties (but that should be done).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature Request: Allow generating an object with a full set of ...
The workflow we use is: Allocate an initial set of defaults in a nested object (note: this isn't fully filled in so won't...
Read more >
Customizing Feature Request List Columns in Savio
By default, your feature request page is set up with the following columns: “Feature Request”, “Feedback”, “MRR”, “Status”, “Priority”, and “ ...
Read more >
Add a Google Analytics 4 property (to a site that already has ...
Copies the property name, website URL, timezone, and currency settings ... To see historical data, use the reports in your Universal Analytics property....
Read more >
Please make it possible to submit variable values via an URL
When embedding a Klip, one can set variables to get different default values while using the same Klip. When embedding a published Dashboard, ......
Read more >
Query (Feature Service/Layer)—ArcGIS REST APIs
Query with returnDistinctResults defaults to using spatial relation ... Hosted feature services using a spatiotemporal data store do not currently support ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found