set<T> method

void set<T>(
  1. String keys,
  2. T value
)

Sets a value by dotiable keys.

Example:

config.set('a.b.c', true); // Update value { "a": { "b": { "c": true } } }

Implementation

void set<T>(String keys, T value) {
  assert(keys.isNotEmpty);

  final cleanedKeys = keys.trimDots();
  final result = switch (dotiable(value)) {
    Map(entries: final entries) => entries
        .map((e) => ('$cleanedKeys.${e.key.toString().trimDots()}', e.value)),
    Iterable(indexed: final indexed) =>
      indexed.map((e) => ('$cleanedKeys.${e.$1}', e.$2)),
    dynamic value => [(cleanedKeys, value)],
  };

  delete(cleanedKeys);
  for (final (key, value) in result) {
    _storage[key] = value;
  }
}