kingwill101 / liquify

Liquid template library
MIT License
5 stars 1 forks source link

Async Filters #5

Open kingwill101 opened 2 months ago

kingwill101 commented 2 months ago

Initially wanted to avoid introducing async everywhere but that will poses an issue for filters that require doing semi long operations.

e.g fetching a json endpoiny

FilterRegistyry.register("getJson", (value, args, namedArgs) async{

 var url =
      Uri.https('www.googleapis.com', '/books/v1/volumes', {'q': '{http}'});

  var response = await http.get(url);
  if (response.statusCode == 200) {
    var jsonResponse =
        convert.jsonDecode(response.body) as Map<String, dynamic>;
    return jsonResponse;
  } else {
    return [];
  }
});
kingwill101 commented 3 weeks ago

@cka29 I want to get this done but not sure of the right approach. It's a bit difficult supporting both async and none async with the same api vs adding say a renderAsync. Which approach would you prefer?