hydrateFromJson static method

void hydrateFromJson(
  1. String jsonString, {
  2. dynamic deserialize(
    1. dynamic data,
    2. List key
    )?,
})

Parses a serialized JSON string and restores the cache entries into BloomData.

Pure Dart and safe for SSR, VM, and browser environments. Extracts the dehydrated state and populates the cache using hydrate.

In the browser, obtain the string content from the DOM element (e.g. via package:web) and pass it to this method before mounting components.

// In client application bootstrap:
const jsonString = '{"queries": [...]}';
BloomData.hydrateFromJson(
  jsonString,
  deserialize: (json, key) => Todo.fromJson(json as Map<String, dynamic>),
);

See also:

Implementation

static void hydrateFromJson(
  String jsonString, {
  dynamic Function(dynamic json, List<dynamic> key)? deserialize,
}) {
  final decoded = jsonDecode(jsonString);
  if (decoded is Map<String, dynamic>) {
    hydrate(decoded, deserialize: deserialize);
  } else if (decoded is Map) {
    hydrate(Map<String, dynamic>.from(decoded), deserialize: deserialize);
  }
}