What is enum DataSource.Link in flutter ferry?

61 Views Asked by At

I am looking at this code in the file operation_response.dart from ferry_exec 0.3.1 https://pub.dev/packages/ferry_exec

enum DataSource {
  /// A placeholder response source which can be used when waiting for another source
  None,

  /// Data originated from the client's [Link]
  Link,

  /// Data originated from the [Cache]
  Cache,

  /// Data originated from a user-provided [OperationRequest.optimisticResponse]
  Optimistic,
}

From the comment, I understand that None is a placeholder while waiting for data, Cache is getting the data from cache, and Optimistic is the data from the request, but I don't understand what Link does. What does it mean and how do we use it?

1

There are 1 best solutions below

0
On

From my observation I see that:

Link acts like http requests and gets the actual data from the server's response.

Optimistic is not really data from the link request, it is more like a placeholder like the none enum that you or the user manually provided (kinda like setStating a variable) to show a default or predicted outcome in the UI while the link request is operating and creating the real response. It's used to make the user experience smoother by showing results quicker than having to load until the link request responds.

The none enum is also a placeholder but doesn't show any value, its just waiting for data to be returned. In either case both Optimistic and None are temporary value, and Link is data received from server.

One way to see its usage in the package examples is to hold ctrl (or command on mac) + click the enum

enter image description here

The examples on there look complex. Since I am in-experienced with this library i'm not sure how to provide a simplified example for the time being