Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoding JSON in an Isolate #103

Open
techouse opened this issue Oct 5, 2022 · 0 comments
Open

Decoding JSON in an Isolate #103

techouse opened this issue Oct 5, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@techouse
Copy link

techouse commented Oct 5, 2022

Hi,

Since the JSON payloads can be quite large, using json.decode() on the main thread could cause janking.

One solution would be to expose a method that does the decoding which defaults to json.decode but allow it to be overridden in order to use compute() or any other Isolate method.

Internally, all references in the package to json.decode(response.body) would have to be replaced with something like await algolia.decodeJson(response.body),

Example:

class Algolia {
  // ... stuff

  /// The method that one can override
  FutureOr<dynamic> decodeJson(String payload) => json.decode(payload);
}

This can then be overridden by the user using compute(), for example

class MyAlgolia extends Algolia {
  // ... stuff
  
  @override
  FutureOr<dynamic> decodeJson(String payload) => compute(json.decode, payload);
}

If you're happy with this approach, I can write up something and submit a PR.

@techouse techouse added the enhancement New feature or request label Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant