saveRollbackPoint method

Future<void> saveRollbackPoint(
  1. String module,
  2. String viewId
)

Save current view definition as rollback point.

Implementation

Future<void> saveRollbackPoint(String module, String viewId) async {
  if (cacheStorage == null || viewService == null) return;

  final cached = await viewService!.cache.get('$module/$viewId');
  if (cached == null) return;

  final key = '$_rollbackPrefix${module}_$viewId';
  final json = jsonEncode(cached.toJson());
  await cacheStorage!.write(key, json);

  // Track rollback history (keep last 5)
  final historyKey = '${key}_history';
  final existing = await cacheStorage!.read(historyKey);
  var history = <String>[];
  if (existing != null) {
    history = (jsonDecode(existing) as List).cast<String>();
  }
  history.insert(0, json);
  if (history.length > 5) history = history.sublist(0, 5);
  await cacheStorage!.write(historyKey, jsonEncode(history));
}