zino-hofmann / graphql-flutter

A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package.
https://zino-hofmann.github.io/graphql-flutter
MIT License
3.23k stars 613 forks source link

Cache parsedData #1342

Closed sandrocsimas closed 1 year ago

sandrocsimas commented 1 year ago

parsedData getter executes parsedFn every time it is called, even when there is no change to the data. Couldn't we cache the parsed data? This would avoid parsing the entire json structure every time we call this getter. Here is the existing code:

  /// If a parserFn is provided, this getter can be used to fetch the parsed data.
  TParsed? get parsedData {
    final data = this.data;
    final parserFn = this.parserFn;

    if (data == null) {
      return null;
    }
    return parserFn(data);
  }