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.

Values API default values

See original GitHub issue

We know that you’re working hard on getting v2 ready for release, so it seems like a good time to formally propose an enhancement to the specification proposed in #202 to support providing default values.

The best syntax I’ve seen so far was proposed by @dancallaghan in his comment on the PR:

static values = {
  url: String,
  refreshInterval: [Number, 300],
  loadOnConnect: [Boolean, true]
}

I love this because it’s non-intrusive and falls back to the current syntax.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:43
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

11reactions
dhhcommented, Dec 10, 2020

I dig this default values design where types are inferred from the values. So 👍 from here.

9reactions
paulozoomcommented, Dec 7, 2020

In that example, [Number, 300] feels redundant because 300 is already a Number. So Stimulus would also need to deal with inconsistency between declared type and default type (or decide not to, and error).

Couldn’t it be instead either the type or the value?

static values = {
  url: String,
  refreshInterval: 300,
  loadOnConnect: true,
}

The type could always be inferred from the value. (Even if typeof Array being Object is a little annoying, the Object case would always be further checked for the Array type.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Web API model validation and default values - Stack Overflow
If I specify a blank value for something (i.e. GET test/123?something= ), then the default value comes into play, and the model is...
Read more >
Default values | Contentful Help Center
Default values are predefined values that are set for specific fields in a content type. They help you bring more consistency into your...
Read more >
Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >
Values API default values · Issue #335 · hotwired/stimulus
The value API is perfect to create those options. Default values would make it simpler rather than having new getters as @olimart pointed....
Read more >
Get Default Values to Create a Record - Salesforce Developers
To get default values with a more lightweight response, use the /ui-api/record-defaults/template/create/{objectApiName} resource.
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