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.

Collecting use cases for async conditional fields

See original GitHub issue

In case you didn’t see it, we’ve released conditional fields!

…however, the current implementation does not support an async hidden calback. This issue exists to collect use cases for async conditional fields so we can provide an alternative mechanism.

Context: why are async conditional fields difficult to implement?

There are a few challenges with making this API async:

  1. Layout critical — This feature has more implications than similar ones (e.g. custom validation) because the layout of the form is dependent on the results of your hidden callback. We want to ensure consistency between the form fields shown and the logic in your hidden callbacks. If we were to naively allow async, we could easily get into situations where multiple mutually exclusive fields are shown at the same time.
    This contrasts with the validation API (which does allow async). With the validation API, it’s much easier to defer and debounce validation results because the layout is not dependent on validation and we can disable the Publish button until all validation has finished running.

  2. Reactivity — Sometimes is async is not enough. If you’re pulling a value asynchronously, you’d probably also like to make this hidden logic re-run when that value changes.

  3. How often the function will be called — Because the condition function takes in the document as an argument, and because we want immediate consistency, it will be called every time the document is updated. You may want to call an API to get a result and this may result in many networks requests.

TL;DR let’s come up with something else!

What are your use cases for async conditional fields?

This issue is to track use cases for conditional fields to see if we can come up with something else that preserves the current simplicity and performance while still doing the job of async conditional fields.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

9reactions
khendriksecommented, Sep 22, 2021

Wondering for this use case: A document has 2 fields:

  1. a reference (or array of references) to another document. That other document might have a field like type
  2. a field that we want to be conditionally hidden if (any of) the reference(s) (field 1) has a specific type
2reactions
djfarlycommented, Jun 8, 2022

My use case is similar to to 3200pros.

We have a configuration type. I’d love to to hide fields based on what the user set in that configuration type. It’s not referenced directly, so I would have used a groq query if async was possible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Consuming the Task-based Asynchronous Pattern
Learn to consume the Task-based Asynchronous Pattern (TAP) when working with asynchronous operations.
Read more >
When to Use (and Not to Use) Asynchronous Programming
As a rule of thumb, asynchronously updating records that are dependent, or depended upon, is generally a bad idea. It's a quick way...
Read more >
for await...of - JavaScript - MDN Web Docs
The for await...of statement creates a loop iterating over async iterable objects as well as sync iterables. This statement can only be used ......
Read more >
Async streams in C# – Deep Dive
Records being read from a database are a great use case for a collection of items to access asynchronously. With the AsAsyncEnumerable() ...
Read more >
Asynchronous invocation - AWS Lambda
When you invoke a Lambda function asynchronously, Lambda places the request in a ... Choose the target type that matches your use case....
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